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

how can I make this platform follow the player?

Asked by 4 years ago

I made a platform that remains a certain distance under the HumanoidRootPart so the player can walk through the air.

while true do
    wait()
            --flyer.Position = char.HumanoidRootPart.Position - Vector3.new(0,3.129,0)
        flyer.CFrame = char.HumanoidRootPart.CFrame - Vector3.new(0,3.129,0)

end

The problem is, the loop moves too slow to keep up with how fast the player walks. How can I work around this?

1 answer

Log in to vote
1
Answered by
ArtBlart 533 Moderation Voter
4 years ago

The problem with your loop is probably the wait(). The default wait time in studio is about 0.03 seconds, and considering a frame in a 60fps environment is about 0.016 seconds, your loop is only running about 30 times per second. There is a way to make this faster though.

Introducing,Heartbeat. This is an event that fires after the physics simulation has finished, making it wait only about 0.016 seconds per wait call. This will essentially double you loop speed.

To use it, simply replace your normal wait() with a:

game:GetService("RunService").Heartbeat:Wait()

Note: Heartbeat fires dependant on how many frames your computer is rendering per second. If your computer can only do 30 frames per second, Heartbeat will only fire 30 times per second.

Hope this helps! If you have any further questions feel free to comment or look things up on the devforum.

Ad

Answer this question