Trip part and velocity

Im trying to make a script where when the parts velocity is 15.904 or above, that the player who got hit by the part sits, and i noticed when the velocity is under that number after it was above… the player still sits when touched, i don’t know how to fix this, can anyone help me?

here is my script:

local trippart = script.Parent
local car1 = script.Parent

function checkVelocity()
	while true do
		wait(0.1) 

		local velocity = car1.Velocity.Magnitude

		if velocity >= 15.904 then
			trippart.Touched:Connect(function(part)
				if part.Parent:FindFirstChild("Humanoid")then
					part.Parent.Humanoid.Sit = true
				end
			end)
		end
	end
end

while true do
	checkVelocity()

end


2 Likes

i dont think you need a loop inside the function

You tried to print velocity? and if yes, even when it prints a number under 15.904, it still sit?

Just noticed something, you didnt disconnect the touched event after it sit. You have 2 choices:

    1. Disconnect the event after it hit
    1. add the “if velocity >= 15.904 then” inside the touched event

Ps: and yeah, as @CarrotusPrime said, you don’t need another loop inside of the function

I think I can help. Try this:

local tripPart = script.Parent
tripPart.Touched:Connect(function(player)
	if player.Parent:FindFirstChild("Humanoid") then
		local velocity = tripPart.Velocity
		if velocity >= 15.904 then
			local humanoid = player.Parent:WaitForChild("Humanoid")
			humanoid.Sit = true
			wait() --however long the player should wait before automatically standing
			humanoid.Sit = false
		end
	end
end)

The Touched:Connect function doesn’t trigger when the player is sitting. Therefore, you might want to try using the SeatPart property of the Humanoid object instead of Touched:Connect