Hi, so I am a beginner at Roblox developpement and I created this script that makes a passcode that open a door with a tween if the code is found.
I asked for help in the RSC’s Discord server because there was a bug (that I fixed) and even before helping me they told be that my code was “ass” and the whole channnel basically just roasted me for no reason.
Now I want some feedback about my code and what is really wrong with it if there is somthing wrong with it in the first place.
local code = tostring(math.random(0, 100))
local door = workspace:WaitForChild("Safes_Models").Safe.Parts.Hinge.Door
local hinge = workspace:WaitForChild("Safes_Models").Safe.Parts.Hinge
local buttons = workspace:WaitForChild("Safes_Models").Safe.Buttons
local display = workspace:WaitForChild("Safes_Models").Safe.Display.DisplayPart.SurfaceGui
local currentInput = ""
local tweenService = game:GetService("TweenService")
local info = TweenInfo.new(1.5, Enum.EasingStyle.Bounce, Enum.EasingDirection.Out, 0, false, 0)
local open = tweenService:Create(hinge, info, {CFrame = hinge.CFrame * CFrame.Angles(0, math.rad(-120), 0)})
local canWrite = true
for i, v in pairs(buttons:GetChildren()) do
v.ClickDetector.MouseClick:Connect(function()
local buttonInput = v.SurfaceGui.TextLabel.Text
if string.lower(buttonInput) == "+" then
if currentInput == code then
display.TextLabel.TextColor3 = Color3.new(0.3, 1, 0)
display.TextLabel.Text = "Correct"
open:Play()
canWrite = false
task.wait(0.5)
canWrite = true
currentInput = ""
display.TextLabel.TextColor3 = Color3.new(1, 1, 1)
display.TextLabel.Text = "Code..."
elseif currentInput ~= code then
display.TextLabel.TextColor3 = Color3.new(1, 0, 0.01)
display.TextLabel.Text = "Incorrect"
canWrite = false
currentInput = ""
task.wait(0.5)
canWrite = true
display.TextLabel.TextColor3 = Color3.new(1, 1, 1)
display.TextLabel.Text = "Code..."
end
elseif string.lower(buttonInput) == "-" then
currentInput = ""
display.TextLabel.TextColor3 = Color3.new(1, 1, 1)
display.TextLabel.Text = "Code..."
else
if canWrite then
currentInput = currentInput..buttonInput
display.TextLabel.Text = currentInput
end
end
end)
end
Thanks for the feedback!