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

How do I get the Part Velocity Y?

Asked by
Hero_ic 502 Moderation Voter
8 years ago
if car.HumanoidRootPart.Velocity.Y < 0 then
    car.HumanoidRootPart.Velocity.Y = 0
end

So I was using this script in my game to stop it from going under 0 randomly but then this error happened.

09:28:51.474 - Y cannot be assigned to 09:28:51.476 - Script 'Players.Player.Backpack.LocalScript', Line 44 09:28:51.477 - Stack End

how would I fix this?

Thanks, KIheros

2 answers

Log in to vote
2
Answered by 8 years ago

You can't set properties of classes that are not Instances

Perhaps try this instead, which will set the Y velocity to 0 when it's lower.

local vel = car.HumanoidRootPart.Velocity
if vel.Y < 0 then
    car.HumanoidRootPart.Velocity = Vector3.new(vel.x,0,vel.z);
end
0
works but you'd need a constant check, he wants to set it to 0 when it reaches less than 0, also vel.x is incorrect vel is humanoidrootpart DragonODeath 50 — 8y
0
Good catch. I forgot to change vel in between deciding which it should refer to. User#6546 35 — 8y
Ad
Log in to vote
1
Answered by 8 years ago

Use the Changed event to detect changes in any property an object. http://wiki.roblox.com/index.php?title=API:Class/Instance/Changed

local part = car.HumanoidRootPart
part .Changed:connect(
    function(property)
        if property == 'Velocity' then --If the Velocity property was changed then
            if part.Velocity.Y < 0 then --If Velocity.Y is less than 0
                part.Velocity = Vector3.new(property.X,0,property.Z)
                --Create a new Vector3 for Velocity, retaining its X and Z values while making Y be 0.
            end
        end
    end
)
0
if property = 'Velocity' then -> if property == 'Velocity' then User#6546 35 — 8y
0
ty for reminder DragonODeath 50 — 8y

Answer this question