Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why does my brick teleport up randomly?

Asked by
Jexpler 63
6 years ago

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

Log in to vote
0
Answered by
Vulkarin 581 Moderation Voter
6 years ago

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)
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. justoboy13 153 — 6y
0
It still jumps up Jexpler 63 — 6y
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 Vulkarin 581 — 6y
0
I literally copied and pasted it. Jexpler 63 — 6y
View all comments (3 more)
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. Jexpler 63 — 6y
0
Is there a way to adjust how long it takes for the platform to move. It's a bit too fast. Jexpler 63 — 6y
0
yeah you can just change the .01 part of the loop Vulkarin 581 — 6y
Ad

Answer this question