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

Best way to change the player's Y velocity?

Asked by
yufa45 0
7 years ago
Edited 7 years ago

I am trying to make a platform that you can jump through from below, but acts as a trampoline when you jump on top of it. I've tried to do it in three ways, but neither of them seems to be perfect:

  1. Bind the following function to the platform's Touched event:
function onTouch(hit)
    if hit.Name == "LeftFoot" or hit.Name == "RightFoot" then
        if hit.Parent.HumanoidRootPart.Velocity.Y < -2 then
            hit.Parent.HumanoidRootPart.Velocity = Vector3.new(0, 80, 0)
        end
    end
end

This works in a Studio simulation, but not on a local server, so apparently I can't write to HumanoidRootPart.Velocity directly.

  1. Modify the code to instead add a BodyVelocityor BodyForceinstance to HumanoidRootPart. This works, but on a local server, it doesn't work quickly enough and the jump only happens after the player has already fallen through the platform.

  2. Set the platform's Velocity.Y to 80, and have the script set CanCollideto true or false depending on what way the player touched the platform. This sometimes makes the player jump up and down very quickly, hovering above the platform — I've noticed the same can happen anytime with platforms above ground level with a nonzero Velocity.Y.

Has anyone succeeded in changing the player's Y velocity through a script before? Maybe there's some simple way to do it I've missed?

0
There shouldn't be a problem giving the rootpart velocity. If so try with torso or head. cabbler 1942 — 7y
0
For some reason none of those work when testing on a local server yufa45 0 — 7y

Answer this question