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
9 years ago
1if car.HumanoidRootPart.Velocity.Y < 0 then
2    car.HumanoidRootPart.Velocity.Y = 0
3end

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 9 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.

1local vel = car.HumanoidRootPart.Velocity
2if vel.Y < 0 then
3    car.HumanoidRootPart.Velocity = Vector3.new(vel.x,0,vel.z);
4end
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 — 9y
0
Good catch. I forgot to change vel in between deciding which it should refer to. User#6546 35 — 9y
Ad
Log in to vote
1
Answered by 9 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

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

Answer this question