Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why does my brick teleport up randomly?

I have a script:

script.Parent.ClickDetector.MouseClick:connect(function()
	local goal = -125.6, -214.86, -386.6
	while script.Parent.Position ~= (goal) do
		local current = script.Parent.Position.Y
		local new = current - .2
		script.Parent.Position = Vector3.new(-125.6, new, -386.6)
		wait(.1)
	end
end)

For some reason, instead of slowly moving down, it teleports higher and stays there.

1 answer

✓ Accepted answer

You didn't make goal a Vector3, if you did print(goal) it would return the first value -125.6 what I would recommend is lerp

Here's an example with what you're doing

script.Parent.ClickDetector.MouseClick:Connect(function()
	local goal = Vector3.new(-125.6, -214.86, -386.6)
	local start = script.Parent.Position

	for i = 0, 1, .01 do
		script.Parent.Position = start:lerp(goal, i)
		wait()
	end
end)

7 comments

0

If you don't know what lerp does, basically "start:lerp(goal, i)" gets the position that is i% of the way from start to goal with i being the decimal percentage.

0

It still jumps up

0

ive tried it in-game and it worked fine. are you sure you made goal a Vector3 like I said? Otherwise it will probably jump up

0

I literally copied and pasted it.

0

Found the issue. There are two anchored blcoks next to it. Removing them fixed it. Gonna experiment to see how close they can be and not interfere with the script.

0

Is there a way to adjust how long it takes for the platform to move. It's a bit too fast.

0

yeah you can just change the .01 part of the loop

This discussion is preserved as it was. New answers, comments, and votes are closed.