1 | if car.HumanoidRootPart.Velocity.Y < 0 then |
2 | car.HumanoidRootPart.Velocity.Y = 0 |
3 | 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
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.
1 | local vel = car.HumanoidRootPart.Velocity |
2 | if vel.Y < 0 then |
3 | car.HumanoidRootPart.Velocity = Vector 3. new(vel.x, 0 ,vel.z); |
4 | end |
Use the Changed event to detect changes in any property an object. http://wiki.roblox.com/index.php?title=API:Class/Instance/Changed
01 | local part = car.HumanoidRootPart |
02 | part .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 = Vector 3. 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 | ) |