cframe = script.Parent.Parent.Door.CFrame function onClick() for i = 1, 60 do cframe = cframe + Vector3.new(0.1, 0, 0) print("loop loop") wait() end wait(5) for i = 1, 60 do cframe = cframe - Vector3.new(0.1, 0, 0) print("looop") wait() end print("done") end script.Parent.ClickDetector.MouseClick:connect(onClick)
This script should make a brick move once a button is clicked, wait a few seconds, then move the brick back to its original place. This script runs in the button, and the button and the brick are in a model together. However, the script fails to move the brick anywhere, and yet it prints the strings in output. Why is the script skipping that part of the loop?
You're not setting the brick's CFrame, but instead, the value of the variable "cframe." To fix this, define the brick as a variable instead, and change its CFrame from there. Here's what it should look like:
cframe = script.Parent.Parent.Door --set this variable to the brick itself function onClick() for i = 1, 60 do cframe.CFrame = cframe.CFrame + Vector3.new(0.1, 0, 0) print("loop loop") wait() end wait(5) for i = 1, 60 do cframe.CFrame = cframe.CFrame - Vector3.new(0.1, 0, 0) print("looop") wait() end print("done") end script.Parent.ClickDetector.MouseClick:connect(onClick)