BodyVelocity Stopping

You should keep track of the part youre attaching the BodyVelocity to while the game is running to make sure there’s only one. And if there is only one make sure it isn’t being added again after being destroyed.

1 Like

Ensure you don’t have another script that creates the body velocity when its destroyed.

1 Like

These are the lines related to the body velocity.

	if State == "holdingW" then
		if Ship.Middle:FindFirstChild("BodyVelocity") then
			Ship.Middle.BodyVelocity.maxForce = Vector3.new(2450,0,2450)
			Ship.Middle.BodyVelocity.Velocity =  Ship.Middle.CFrame.lookVector*-40*2
		else
			local BodyVelocity = Instance.new("BodyVelocity")
			BodyVelocity.Parent = Ship.Middle
			Ship.Middle.BodyVelocity.maxForce = Vector3.new(2450,0,2450)
			Ship.Middle.BodyVelocity.Velocity = Ship.Middle.CFrame.lookVector*-40*2
		end
	end
	if State == "notholdingW" then
		if Ship.Middle:FindFirstChild("BodyVelocity") then
			Ship.Middle.BodyVelocity:Destroy()
		end
	end

Try adding a print after “if Ship.Middle:FindFirstChild(“BodyVelocity”) then” to make sure it finds the BodyVelocity. If the print works and the BodyVelocity is found then go to the Explorer and find where its parented and see if only one is being created.

I’ve done that already, the code is completely fine, function-wise.

I don’t really know what the problem is, but I can tell you to use functions to organize the way your scripts work. They’re useful for figuring out why something like this is happening, and easier to read.

Also I think instead of setting the Velocity to () you should set it to “speed” and when you press let’s say S speed = 0, then when your velocity is moving * speed it will stop moving. You really should use functions for this though, like “UpdateVelocity” rather than using an if statement, because sometimes one if statement can overlap another causing it to not work the way you planned it to.

I’m aware functions would be more organised however, this is just an alpha test, as I said above, functioning-wise the code is fine, nothing breaks, nothing happens that it shouldn’t. My only problem is removing the BodyVelocity doesn’t stop the Part from actually moving.

You checked the part it’s parented to in the explorer and only one is found right? And deletes when W is released?

Yes, I’ve checked that many times

Are you sure that the velocity is destroyed?

I’m certain, I always check the explorer when testing.

Maybe a different BodyVelocity is being applied when this one gets destroyed. Are they any others that are created?

No, I checked this already, way before making this post

I just tried making a part with the exact same MaxForce as yours and changed the X to 5, then made a script to Destroy it and it still works. I have no idea why destroying it doesn’t work for you sorry :confused:

I’ll figure something out then, thanks anyway.

Can you show the local script where you detecting the input, and is the network owner of the ship the client or server? or are you using remote events?

I’m using UIS to detect when W is pressed, then setting a hold value to true, vice-versa for inputended to show when it’s released. Then i’m using RunService to check when holding is set to true or false.
Here is the run service function, where the remote is fired:

RunService.RenderStepped:Connect(function()
	if holdingW == true then
		local State = "holdingW"
		AddVelocityForward:FireServer(State)
		end
		if holdingW == false then
			local State = "notholdingW"
			AddVelocityForward:FireServer(State)	
	end
end)

Maybe only pass the AddVelocityForward when the button is pressed using InputService.

For loop through all parts of the character and set the velocity to vector3.new() aka 0.
And if you want to be extra sure that it stops, anchor the player’s rootpart as well.

Ok so it turns out, it doesn’t stop if there’s another body movement instance inside the part, when the velocity is on its own then it’ll stop but if it’s with let’s say a bodygyro then it won’t stop