Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I get the Part Velocity Y?

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

✓ Accepted answer

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

2 comments

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

0

Good catch. I forgot to change vel in between deciding which it should refer to.

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
)

2 comments

0

if property = 'Velocity' then -> if property == 'Velocity' then

0

ty for reminder

This discussion is preserved as it was. New answers, comments, and votes are closed.