Car run over script not working

I made a script that if the player is hit by the bumper of a car and the car gear is in 2nd the player get falls over, but it doesnt seem to work at all, im sure it works but it isnt for some reason, any help maybe?

script.Parent.Touched:Connect(function(HitPart)
	local Character = HitPart.Parent
	local carspeed = script.Parent.Parent.ebux:WaitForChild("Gear").Value
	local Humanoid = Character:FindFirstChild("Humanoid")
	if Humanoid ~= nil and carspeed == 2 then
		Humanoid.Sit = true
		Humanoid.Health -= 35
		script.Parent.Sound:Play()
		script.Disabled = true
		wait(3)
		script.Disabled = false
		Humanoid.Sit = false
		script.Parent.Sound:Stop()
	end
end)

You’re disabling the script while it’s running.

well it turns back on after the wait, it was working until i put the call

if humanoid ~= nil and carspeed == 2 then

@RevanNight
any advice, or some help to fix this?

Once you disable the script through the same script, you can’t enable it again unless you enable it manually, or enable it with another script.

Also, instead of enabling and disabling the script, you should use debounces as they are more efficient.

1 Like

Lol well, it still works when i remove the call

if humanoid ~= nil and carspeed == 2 then

either way that isnt the problem, the script activates itself, its just that it doesnt work when I put carspeed == 2

I’m assuming the car could be traveling more than 2 studs per second, try changing it to;
if humanoid ~= nil and carspeed >= 2 then

Okay, thanks alot, ill try this out right now

Yeah so its not working, basically carspeed is like a value that measured by the car gear, so the script basically tells the gear value to turn into 2 after an amount of rpm, so what my attempt to do was make it so the if the car is put to second gear or above, the player can be hit by the vehicle

But if the car is below 2nd gear like in first gear the player cant get hit by the car because it isnt going fast enough

@CrazyAlternetive

What im trying to prevent here is if the car is just standing still not driving at all and a player touches the car you wont take damage and fall over

I see, do you mind showing the script that changes the car gear value?

sure lemme get a line

β€˜β€™β€™β€™β€™β€™β€™β€™β€™β€™β€™β€™β€™β€™β€™β€™β€™β€™β€™β€™β€™β€™β€™β€™β€™β€™

	if (canShift==true) then
		if seat.Throttle==1 and car.RPM.Value>6.6 and gear<numgears and not r then
			shift(1)
		elseif seat.Throttle<1 and car.RPM.Value<4 and gear>1 then
			shift(-1)
		end
	end
end)

The script is really messy, my bad lol.

Check to see if carspeed is even reaching 2 with a print before the if statement if it doesn’t print 2 than your issue is probably in your other script. Also if your gears go above 2 change it to carspeed >= 2.