I have a script that's supposed to move a part. For some reason, it teleports it up. Why?
script.Parent.ClickDetector.MouseClick:Connect(function(plr) for i = 1, 52 do local door1 = script.Parent.Parent.Door1 local x1 = door1.Position.X local y1 = door1.Position.Y local z1 = door1.Position.Z local newx1 = x1 + .1 door1.Position = Vector3.new(newx1,y1,z1) end end)
I believe you're looking to tween the part to move upwards. What's happening is that the loop finishes before you can see it. Add a wait()
inside the loop if you'd like to see it.
Also your for-loop has an increment parameter than you can use instead of adding .1 to the position X value every loop.
--This doesn't need to be in the loop. local door1 = script.Parent.Parent.Door1 script.Parent.ClickDetector.MouseClick:Connect(function(plr) --This for loop is saying: From 1 count to 52 by .1 for i = 1, 52, .1 do --Since we're only adding .1 to get to 52 we can just use a new --Vector3 and add it to our door's current position door1.CFrame = door1.CFrame + Vector3.new(i, 0, 0) wait() --so we can see it move. end end)
Alternatively and even more effectively, you should be using TweenService to tween parts from one position to the next.
Use this instead
script.Parent.ClickDetector.MouseClick:Connect(function(plr) for i = 1, 52 do local door1 = script.Parent.Parent.Door1 local x1 = door1.Position.X local y1 = door1.Position.Y local z1 = door1.Position.Z local newx1 = x1 + .1 door1.CFrame = CFrame.new(newx1,y1,z1) end end)
You can't teleport move things using the Position property, use CFrame and it's recommended to use tweening instead