Hi devs, today i wanted to do a door.
I’ve put a script that makes the textlabel text into a random number for every server using math.random.
So, there is a door, if you put the correct code in the door, you can go through it.(The code you’ve put is showed in the ?? textlabel that you can see in the image)
So, my problem is, when i try to put the code, the textlabel that should say what code i put, is white, clear and enter buttons aren’t working.
These are my scripts:
Script for the door:
local door = script.Parent.Door
local textLabel = script.Parent.Keypad.CodeEntered.SurfaceGui.TextLabel
local clearButton = script.Parent.Keypad.Clear
local enterButton = script.Parent.Keypad.Enter
Instance.new("ClickDetector", clearButton)
Instance.new("ClickDetector", enterButton)
for _, button in ipairs (script.Parent.Keypad.Digits:GetChildren()) do
Instance.new("ClickDetector", button)
end
local code = ""
local function updateCodeLabel(button)
textLabel.Text = code
end
local function clearCode()
code = ""
updateCodeLabel()
end
local function checkCode()
if code == script.Parent.Code.SurfaceGui.Code.Text then
door.CanCollide = false
door.Transparency = 0.5
clearCode()
else
clearCode()
end
end
clearButton.ClickDetector.MouseClick:Connect(function()
clearCode()
end)
enterButton.ClickDetector.MouseClick:Connect(function()
checkCode()
end)
textLabel:GetPropertyChangedSignal("Text"):Connect(function()
local newText = textLabel.Text
local lastChar = string.sub(newText, -1)
if tonumber(lastChar) ~= nil then
code = code .. lastChar
updateCodeLabel()
end
end)
for _, button in ipairs (script.Parent.Keypad.Digits:GetChildren()) do
if button:IsA("Part") then
button.ClickDetector.MouseClick:Connect(function()
updateCodeLabel(button)
end)
else
print("It's not a part!")
end
end
Script for the random code:
local textLabel = script.Parent
local randomNumber = math.random(100000000, 999999999)--9
textLabel.Text = randomNumber
Sorry for my bad english.
Thanks!
This happens when i click a digit: