Door = game.Workspace.Door Button = game.Workspace.Button local buttonPressed = false Workspace.Button.Touched:connect(function(hit) if not buttonPressed then buttonPressed = true for i=0,5,.1 do Door.CFrame = CFrame.new(86.48, 4.89, -i) wait(3) Door.CFrame = CFrame.new(86.48, 4.89, i) buttonPressed = false end end end)
My first problem is the part (Door) is moved on the Z axis to what I guess is either 0 or .1 while I just want to stay in it's current place (86.48, 4.89, -35.935) and just move to the left 5 studs, which is working. I also don't understand how to make it move back into place after 3 seconds but isn't working and I don't have any idea how to fix this one.
SlickPwner is wrong about a numeric for loop only using two numbers. The third, step, is usable, your code is just messed up in other ways.
First of all, your debounce needs to open again after the loop, not inside it.
What it looks like to me is you want to slide the door open, wait three seconds, then slide it shut. This requires two loops, which each need a wait() inside them.
Lastly, you have to add the Door's initial Z-position to the CFrame when moving it, or else it will be set to i
, which is why it was teleporting to near the origin.
Door = game.Workspace.Door Button = game.Workspace.Button local startZ = Door.Position.Z local buttonPressed = false Workspace.Button.Touched:connect(function(hit) if not buttonPressed then buttonPressed = true for i = 5, 0, -.1 do Door.CFrame = CFrame.new(86.48, 4.89, startZ + i) wait(.1) end wait(3) for i = 0, 5, .1 do Door.CFrame = CFrame.new(86.48, 4.89, startZ + i) wait(.1) end buttonPressed = false --This needs to be outside the loop, or else end end)
Side note: why does everybody use Spaces instead of Tabs for indentation? It's so annoying!
You have a few problems here. First of all, you have 3 numbers separated by commas in the for line, when you should only have 2.
Secondly, you have messed up the code inside the for loop. I'll rewrite your code, and explain it in comments.
Door = game.Workspace.Door Button = game.Workspace.Button local buttonPressed = false Button.Touched:connect(function(hit) --You don't need Workspace if you already declared the variable. if buttonPressed == false then --I prefer "== false" to "not," just personal preference. buttonPressed = true for i=1,10 do Door.CFrame = CFrame.new(86.48, 4.89, i) wait(.1) end end end)
This should work. Hope I helped!