Touched event not firing

I’ve made a touched event when a part is touched, but when the thing that I want to fire it (a MeshPart) touches it, it doesn’t fire. I’ve tried testing it with other parts, and sometimes it works.

Server script inside the part:

script.Parent.Touched:Connect(function(hit)
	print("e")
	if hit.Name == "Train" and hit:FindFirstChild("Moving") then
		print("a")
		local explos = Instance.new("Explosion")
		explos.Position = script.Parent.Position
		explos.Parent = script.Parent
		explos.BlastPressure = .4
		hit.Parent.TrainHandler.Disabled = true
		hit.Chug:Stop()
		for i = 20,1,-1 do
			local End = hit.Parent:GetPrimaryPartCFrame()*CFrame.Angles(math.rad(90),0,0)
			local start = hit.Parent:GetPrimaryPartCFrame()
			hit.Parent:SetPrimaryPartCFrame(start:lerp(End,i))
		end
		script.Parent.Explosion:Play()
	end
end)

Any help would be appreciated. :slightly_smiling_face:

2 Likes

Is it a local script? If it is, that explains it

1 Like

It clearly says he put it in a (Server)Script inside the part, so he should be fine on the type of script, please read through before jumping ahead and trying to answer questions, that are already provided in the topic.

@Fondatix I tried this and it worked perfectly fine, did you maybe accidentally put it inside a descendant or something?

5 Likes

Oop, I tend not to read the titles before the script from past experience. Thank you for noticing!

@Fondatix, can we see the parenting of the model?

1 Like

image

Also, both parts are anchored.

I also tried welding an unanchored part to the front of the train and listening for that but that didn’t work.

Touched events do not fire for anchored parts. Touched will only fire for parts that intersect through physics simulation - that is, one part touches another naturally. This is noted in the Touched documentation page and explained in the Anchored documentation page.

8 Likes

Do both parts need to be anchored? I tried welding an unanchored part to the front of the train and listening for that but that didn’t work.

The post approval had said that touch events won’t fire for parts that are anchored, one part has to move physically on it’s own for a better understanding. NO CFRAME MOVING!

Yeah, but I welded an unanchored part to the front of the train, and it didn’t even pick that up.

Is the front of the train anchored? If so then that welded part also acts as an anchored part as said here: BasePart | Documentation - Roblox Creator Hub

The part which the welded part is welded to is anchored, but the welded part isn’t anchored.

Yes, but that still makes both parts anchored as said in the article I provided above.

What would be the best solution then?

Does the front of the train have to be anchored if it can be welded by other unachored parts, you could probably do that.

Yeah it has to be anchored for the train to work.

Why not make a fake base for the engine and have it touch that instead

Not sure what you mean by that, could you elaborate?

So you know when people create custom characters they have a “FakeHead” you can make a non-colliding invisible base of the train and have the part touch that instead of the actual engine.

(You can make an invisible part that goes around the whole engine and set can collide to off)

Still not sure what you mean by that.

1 Like

Here is a clip of what I mean:

Big mesh part is the “Engine” and transparent part is the “FakeBase”