I want a gate (Model) that slides into one position on click and slides back into its original position on second click. almost everything works well except for when i change the ".01" to anything different, it doesn't open nor close anymore.
script.Parent.ClickDetector.MouseClick:connect(function() local state = script.Parent.Parent.State if state.Value == false then state.Value = true local Gate = script.Parent.Parent.Gate for i = 0, .7, .01 do Gate:SetPrimaryPartCFrame(Gate:GetPrimaryPartCFrame() * CFrame.new(0,0,-i)) end else state.Value = false local Gate = script.Parent.Parent.Gate for i = 0, .7, .01 do Gate:SetPrimaryPartCFrame(Gate:GetPrimaryPartCFrame() * CFrame.new(0,0,i)) end end end)
Based on you telling me you are changing it to 1, here is the problem
your for
loop takes 3 arguments: i, the ending number and the increment (These are not their exact names, just what they are)
your code that you posted goes up by .01 up to .7 every time, starting at 0. This works because both i and the increment are smaller than the end.
when you change it to 1, it won't work well because your asking it to go from 0 to 1 on the first round. since 1>0.7, the loop has executed the amount of times you asked it to and will end.