If Part touch to Part the script run (Train Traffic Light)

I am trying to script if part touched a another part the script below will run but it doesn’t work.
If you have any idea please help me.

local Signal1 = script.Parent.SignalParts.Red
local Signal2 = script.Parent.SignalParts.Yellow
local Signal3 = script.Parent.SignalParts.Green

Touch.Touched:Connect(function(Hit)
	local Humanoid = Hit.Parent:FindFirstChild("Humanoid")
	if Humanoid then
		Signal1.Material = Enum.Material.Neon
		Signal2.Material = Enum.Material.SmoothPlastic
		Signal3.Material = Enum.Material.SmoothPlastic
		wait(60)
		Signal1.Material = Enum.Material.SmoothPlastic
		Signal2.Material = Enum.Material.Neon
		Signal3.Material = Enum.Material.SmoothPlastic
		wait(30)
		Signal1.Material = Enum.Material.SmoothPlastic
		Signal2.Material = Enum.Material.SmoothPlastic
		Signal3.Material = Enum.Material.Neon
	end
end)

Simply just use a touched event? It will run if anything touches the part?

Okay let me try that. Please wait.

Add debounce?

local deb = false
local Signal1 = script.Parent.SignalParts.Red
local Signal2 = script.Parent.SignalParts.Yellow
local Signal3 = script.Parent.SignalParts.Green

Touch.Touched:Connect(function(Hit)
if not deb then
deb = true
	local Humanoid = Hit.Parent:FindFirstChild("Humanoid")
	if Humanoid then
		Signal1.Material = Enum.Material.Neon
		Signal2.Material = Enum.Material.SmoothPlastic
		Signal3.Material = Enum.Material.SmoothPlastic
		wait(60)
		Signal1.Material = Enum.Material.SmoothPlastic
		Signal2.Material = Enum.Material.Neon
		Signal3.Material = Enum.Material.SmoothPlastic
		wait(30)
		Signal1.Material = Enum.Material.SmoothPlastic
		Signal2.Material = Enum.Material.SmoothPlastic
		Signal3.Material = Enum.Material.Neon
end
deb = false
	end
end)

Np that does not work. I dont know why.

No. That does not work too. Hmm.

I dont understand what you’re trying to do? can you explain?

Okay. So I am currently making the train system and that script is for traffic light. In train down there is a part.
Below is the train scan part.
image
below is traffic scan light.


if the train part touched to traffic scan. The right red will be neon part. And others will be smoothplastic.
image

That is I want.

Is the train moving from a script? Because if not, touched events don’t fire for anchored parts.

But I don’t want to use RemoveEvent. (I wanna make it 1 script simple.)

image

That is script inside. And if train part touched the Touch part script will run.

OH wait. REALLY?? It doesntt work for anchored parT?? OH.

How is the train moving, though? A tween? A loop? Is it anchored?

So I should use weld script? or no?

Not anchored. But I dont know how. My friend made original drive system. Let me see.

However you want to do it, just make sure the .Touched event is actually firing.

https://create.roblox.com/docs/reference/engine/classes/BasePart#Touched

1 Like

Can you do a bit changes? I don’t know these types of script. I can only do beginner script. Also, I am Japanese soo…

I wouldn’t use a touched event. That’s really error prone, because if the part somehow gets destroyed, the system won’t work. I would check if it surpasses a certain threshold, like if the train’s x value is greater than a certain number.

1 Like

They do fire when anchored.
Funny_Limit_Thingy.