Table of Contents

Solve Password Script

Finished Product

Create features

Create a block when clicked will show the UI

Design UI

Script

local treasure_block_id = nil ---- Replace your block id here
local uiid = nil ---- Replace your UI ID here
local number_1_ = nil ----  Replace 1st number here (password 1)
local number_2_ = nil ----  Replace 2nd number here (password 2)
local number_3_ = nil ----  Replace 3rd number here (password 3)
local button_1 = nil ---- Replace the ID of first button here 
local button_2 = nil ---- Replace the ID of second button here
local button_3 = nil ---- Replace the ID of third button here
local number0 = "10266"
local number1 = "10267"
local number2 = "10268"
local number3 = "10269"
local number4 = "10270"
local number5 = "10271"
local number6 = "10272"
local number7 = "10273"
local number8 = "10274"
local number9 = "10275"
-------------Don't edit anything below-------------
function click_to_treasure_block(e) 
    if e.blockid == treasure_block_id then
        Player:openUIView(e.eventobjid, uiid)
    end
end
 
ScriptSupportEvent:registerEvent("Player.ClickBlock", click_to_treasure_block)
 
local click_time_of_button_1 = 0
 
function number_1(e) 
    if e.uielement == button_1 then 
        click_time_of_button_1 = click_time_of_button_1 + 1 
        if click_time_of_button_1 == 10 then
            click_time_of_button_1 = 0 
        end 
    end
    if click_time_of_button_1 == 0 then 
        Customui:setTexture(e.eventobjid, uiid, button_1, number0)
    elseif click_time_of_button_1 == 1 then 
        Customui:setTexture(e.eventobjid, uiid, button_1, number1)
    elseif click_time_of_button_1 == 2 then 
        Customui:setTexture(e.eventobjid, uiid, button_1, number2)
    elseif click_time_of_button_1 == 3 then 
        Customui:setTexture(e.eventobjid, uiid, button_1, number3)
    elseif click_time_of_button_1 == 4 then 
        Customui:setTexture(e.eventobjid, uiid, button_1, number4)
    elseif click_time_of_button_1 == 5 then 
        Customui:setTexture(e.eventobjid, uiid, button_1, number5)
    elseif click_time_of_button_1 == 6 then 
        Customui:setTexture(e.eventobjid, uiid, button_1, number6)
    elseif click_time_of_button_1 == 7 then 
        Customui:setTexture(e.eventobjid, uiid, button_1, number7)
    elseif click_time_of_button_1 == 8 then 
        Customui:setTexture(e.eventobjid, uiid, button_1, number8)
    elseif click_time_of_button_1 == 9 then 
        Customui:setTexture(e.eventobjid, uiid, button_1, number9)
    end
    if number_1_ == click_time_of_button_1 and number_2_ == click_time_of_button_2 and number_3_ == click_time_of_button_3 then 
        Player:notifyGameInfo2Self(e.eventobjid, "you solved the password correctly")
    end
end
 
 
ScriptSupportEvent:registerEvent("UI.Button.Click", number_1)
 
local click_time_of_button_2 = 0
 
function number_2(e) 
    if e.uielement == button_2 then 
        click_time_of_button_2 = click_time_of_button_2 + 1 
        if click_time_of_button_2 == 10 then
            click_time_of_button_2 = 0 
        end 
    end
    if click_time_of_button_2 == 0 then 
        Customui:setTexture(e.eventobjid, uiid, button_2, number0)
    elseif click_time_of_button_2 == 1 then 
        Customui:setTexture(e.eventobjid, uiid, button_2, number1)
    elseif click_time_of_button_2 == 2 then 
        Customui:setTexture(e.eventobjid, uiid, button_2, number2)
    elseif click_time_of_button_2 == 3 then 
        Customui:setTexture(e.eventobjid, uiid, button_2, number3)
    elseif click_time_of_button_2 == 4 then 
        Customui:setTexture(e.eventobjid, uiid, button_2, number4)
    elseif click_time_of_button_2 == 5 then 
        Customui:setTexture(e.eventobjid, uiid, button_2, number5)
    elseif click_time_of_button_2 == 6 then 
        Customui:setTexture(e.eventobjid, uiid, button_2, number6)
    elseif click_time_of_button_2 == 7 then 
        Customui:setTexture(e.eventobjid, uiid, button_2, number7)
    elseif click_time_of_button_2 == 8 then 
        Customui:setTexture(e.eventobjid, uiid, button_2, number8)
    elseif click_time_of_button_2 == 9 then 
        Customui:setTexture(e.eventobjid, uiid, button_2, number9)
    end
    if number_1_ == click_time_of_button_1 and number_2_ == click_time_of_button_2 and number_3_ == click_time_of_button_3 then 
        Player:notifyGameInfo2Self(e.eventobjid, "you solved the password correctly")
    end
end
 
 
ScriptSupportEvent:registerEvent("UI.Button.Click", number_2)
 
local click_time_of_button_3 = 0
 
function number_3(e) 
    if e.uielement == button_3 then 
        click_time_of_button_3 = click_time_of_button_3 + 1 
        if click_time_of_button_3 == 10 then
            click_time_of_button_3 = 0 
        end 
    end
    if click_time_of_button_3 == 0 then 
        Customui:setTexture(e.eventobjid, uiid, button_3, number0)
    elseif click_time_of_button_3 == 1 then 
        Customui:setTexture(e.eventobjid, uiid, button_3, number1)
    elseif click_time_of_button_3 == 2 then 
        Customui:setTexture(e.eventobjid, uiid, button_3, number2)
    elseif click_time_of_button_3 == 3 then 
        Customui:setTexture(e.eventobjid, uiid, button_3, number3)
    elseif click_time_of_button_3 == 4 then 
        Customui:setTexture(e.eventobjid, uiid, button_3, number4)
    elseif click_time_of_button_3 == 5 then 
        Customui:setTexture(e.eventobjid, uiid, button_3, number5)
    elseif click_time_of_button_3 == 6 then 
        Customui:setTexture(e.eventobjid, uiid, button_3, number6)
    elseif click_time_of_button_3 == 7 then 
        Customui:setTexture(e.eventobjid, uiid, button_3, number7)
    elseif click_time_of_button_3 == 8 then 
        Customui:setTexture(e.eventobjid, uiid, button_3, number8)
    elseif click_time_of_button_3 == 9 then 
        Customui:setTexture(e.eventobjid, uiid, button_3, number9)
    end
 
    if number_1_ == click_time_of_button_1 and number_2_ == click_time_of_button_2 and number_3_ == click_time_of_button_3 then 
        Player:notifyGameInfo2Self(e.eventobjid, "you solved the password correctly")
    end
end
 
ScriptSupportEvent:registerEvent("UI.Button.Click", number_3)

Explanation

Variable Declarations

local treasure_block_id = nil
local uiid = nil
local number_1_ = nil
local number_2_ = nil
local number_3_ = nil
local button_1 = nil
local button_2 = nil
local button_3 = nil

Number Texture IDs

local number0 = "10266"
local number1 = "10267"
local number2 = "10268"
local number3 = "10269"
local number4 = "10270"
local number5 = "10271"
local number6 = "10272"
local number7 = "10273"
local number8 = "10274"
local number9 = "10275"

These variables represent texture IDs for the digits 0-9. They are used to update the UI buttons to display the corresponding numbers.

Click Event on the Treasure Block

function click_to_treasure_block(e) 
    if e.blockid == treasure_block_id then
        Player:openUIView(e.eventobjid, uiid)
    end
end
 
ScriptSupportEvent:registerEvent("Player.ClickBlock", click_to_treasure_block)

When the player clicks on the block with ID treasure_block_id, the UI with ID uiid is opened. ScriptSupportEvent:registerEvent registers the click_to_treasure_block function to handle the block click event.

Button 1 Handling

local click_time_of_button_1 = 0
 
function number_1(e) 
    if e.uielement == button_1 then 
        click_time_of_button_1 = click_time_of_button_1 + 1 
        if click_time_of_button_1 == 10 then
            click_time_of_button_1 = 0 
        end 
    end
    -- Update button texture based on the number
    if click_time_of_button_1 == 0 then 
        Customui:setTexture(e.eventobjid, uiid, button_1, number0)
    elseif click_time_of_button_1 == 1 then 
        Customui:setTexture(e.eventobjid, uiid, button_1, number1)
    ----- etc. (similar code for numbers 2 to 9)
    end
 
    if number_1_ == click_time_of_button_1 and number_2_ == click_time_of_button_2 and number_3_ == click_time_of_button_3 then 
        Player:notifyGameInfo2Self(e.eventobjid, "you solved the password correctly")
    end
end
 
ScriptSupportEvent:registerEvent("UI.Button.Click", number_1)

Button 2 and 3 is the same

Password Check

    if number_1_ == click_time_of_button_1 and number_2_ == click_time_of_button_2 and number_3_ == click_time_of_button_3 then 
        Player:notifyGameInfo2Self(e.eventobjid, "you solved the password correctly")
    end

If you have any questions about Developer Tools, feel free to join our official discord server Mini World Global DEV discord