Efficient & working way to determine whether the train is in the platform?

Hello again, I’ve been working on a train simulator and I need to determine whether the train is in the platform, so it can safely open the doors.

Before the method I’m using now (which doesn’t work) I used a for loop to cycle through all the parts in the platform region, to determine whether this specific train was in the platform. However this system wouldn’t work in the long term (and even the one in this new method), as if any train entered that region (which includes platform 1 & 2) and had the same Front & Back Sensor, any trains which has this station as the next station, would be considered as “in the platform”, but they could be miles away. Also the other problem is that the variable ‘isinPlatform’ was not changing to false when the train left.

I tried switching to the method below, but this doesn’t work at all! Could someone please help me?

if station then
	if not workspace:GetPartsInPart(station)["RearSensor"] and not workspace:GetPartsInPart(station)["FrontSensor"] and hasLoaded ~= true then
		isInPlatform = false	
	elseif workspace:GetPartsInPart(station)["RearSensor"] and hasLoaded ~= true then
		stationIndicator.DoorHint.Visible = true
		stationIndicator.DoorHint.Text = "'T' to load passengers."
		stationIndicator.DoorHint.Bar.Size = UDim2.new(0, 0, 0, 2)
		isInPlatform = true	
	elseif workspace:GetPartsInPart(station)["FrontSensor"] then
		stationDistance = 0
	end	
else
	stationIndicator.DoorHint.Visible = false
	stationIndicator.DoorHint.Bar.Size = UDim2.new(0, 0, 0, 2)
	isInPlatform = false	
end
2 Likes

First of all create a part which encloses the platform and then use ZonePlus or OT&AM (more performant) to create a new zone/area from that part and listen for their respective object entered listeners and check if the entered object is a part of the train model, or just create a root part at the center of the train and check for that part.

2 Likes

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