Why is my emergency brake function not working?

My train system has an emergency brake function, so basically if it stops at a station, the brakes apply.
However it just stopped working, around the time I started building up my script, and there is no error?

local function emergencyBrake()
	targettedThrottle = 0
	targettedBrake = 0
	Velocity = 0
		
	RemoteClientEvent:FireServer("base", {action = "MovementUpdate", throttle = targettedThrottle, brake = targettedBrake})
end
coroutine.wrap(function()	
	while eBrakeActive == true do
		emergencyBrake()

		task.wait(.1)
	end	
end)()

Can anyone please provide some insight into this?

Edit: Also even without the coroutine it doesn’t work :stuck_out_tongue:

4 Likes

Use print statements in each area to see what runs.

1 Like

Nothing prints for some reason…

Maybe call the emergency brake function when ebrakeactive changes.

Does emergency break ever get set to true?

It gets set to true when the train has stopped at a station

1 Like

Have you printed ebrakeactive to see if it actually changes when the trains stopped?

It just did that, it changes when the train stops

1 Like

The problem is that this is not wrapped in a whole true do. While loops stop and do not start again.

1 Like

Thanks a lot! It finally worked!

3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.