Need help with a keycode door

Hello, just a heads up that I am very very new to scripting, and this is my first time trying to script something.

I am basically trying to create a keypad that opens a door when the correct code is entered. I tried following a tutorial on YT by SteelKidGaming, but I can’t seem to make it work for me.

Here is what I did:

  • Each button has a script, click detector, surfacegui, and a text label.
  • The script I used (from the tutorial), minus the clicking sound he used

db = false
script.Parent.ClickDetector.MouseClick:Connect(function(player)
if db == false then
db = true
script.Parent.Position = script.Parent.Position - Vector3.new(0.2,0,0)
script.Parent.Parent.CodeShower.SurfaceGui.TextLabel.Text = script.Parent.Parent.CodeShower.SurfaceGui.TextLabel.Text…script.Parent.Name
wait(0,1)
script.Parent.Position = script.Parent.Position + Vector3.new(0.2,0,0)
wait(0,1)
db = false
end
end

From my understanding, the script.Parent.Position = script.Parent.Position part basically makes the button retract when pressed, but when I tested it, the part does not retract. Does this have something to do with the part being anchored?

And then the script.Parent.Parent.CodeShower.SurfaceGui.TextLabel.Text = script.Parent.Parent.CodeShower.SurfaceGui.TextLabel.Text…script.Parent.Name part should be displaying the button pressed. I made sure to rename the parts like the CodeShower, too.

Inside the CodeShower part, I only have a surfaceGui and an empty text label, as per the tutorial.

The buttons seem to be unpressable as the buttons don’t retract at all when I test it, and it doesn’t even display the text on the CodeShower.

Thank you.

Make sure to cover your code in 3 backticks for the start and end.

Example:

`‌`‌`
print("Hello world!")
`‌`‌`

-- Don't copy those backticks. They have zero width joiners in-between them.

Your code (formatted):

db = false
script.Parent.ClickDetector.MouseClick:Connect(function(player)
	if db == false then
		db = true
		script.Parent.Position = script.Parent.Position - Vector3.new(0.2,0,0)
		script.Parent.Parent.CodeShower.SurfaceGui.TextLabel.Text = script.Parent.Parent.CodeShower.SurfaceGui.TextLabel.Text .. script.Parent.Name
		wait(0,1)
		script.Parent.Position = script.Parent.Position + Vector3.new(0.2,0,0)
		wait(0,1)
		db = false
	end
end

It seems you used commas in the wait() function. Note that this actually means that you’re putting in two arguments inside, while wait() only takes in one, which must’ve caused an error.

wait(0.1) -- Is one argument.

wait(0,1) -- Is the same as...
wait(0, 1) -- They're two arguments.

Anchored or not, you can still edit the Position property.

You were right, it was the commas. It seems to be reflecting the value on the CodeShower now.

Thank you so much!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.