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

Model glitching when using :MoveTo?

Asked by 1 year ago

I am making an elevator and when I call the first :MoveTo it moves up about 2-4 studs and then immediately continues the script and works flawlessly after. The reason I have a problem with this is that it teleports the player under the elevator ending with them plummeting into the void! I don't know if another method of moving the model would fix the problem or if its a completely different problem. Thanks for your help!

local Bumper = script.Parent
local Elevator = script.Parent.Parent.Parent
local debounce = false

Bumper.Touched:Connect(function(hit)
    if debounce == false then
        if hit.Parent.Name == "Cart" then
            debounce = true
            wait(0.5)
            local EleYCheck = 14.2
            while EleYCheck ~= 64.2 do
                EleYCheck += 0.01
                Elevator:MoveTo(Vector3.new(-15.587, EleYCheck, -42.972))
                wait(0.01)
            end
            wait(10)
            while EleYCheck ~= 14.2 do
                EleYCheck -= 0.01
                Elevator:MoveTo(CFrame.new(-15.587, EleYCheck, -42.972))
                wait(0.01)
            end
            wait(3)
            debounce = false
        end
    end
end)

1 answer

Log in to vote
0
Answered by
NykoVania 231 Moderation Voter
1 year ago

Use TweenService to slowly move the elevator. I believe your issue is that the player is not moving with the elevator and gets glitched under, you could do that or use :MoveTo on the player aswell.

Ad

Answer this question