Why does my touched function only work if a player touches it

I just want it to print out touched.Parent it use to react to everything that touched it now it doesn’t?

script.Parent.Touched:Connect(function(touched)
	print(touched.Parent)
end)
2 Likes

So do you want to print the object value of the touches object or the name?

1 Like

Just the name of the part it touched I tried touched.Parent.Name which didn’t work, it’s probably some small part of the code I missed but I have this and here’s what happens.

script.Parent.Touched:Connect(function(touched)
	script.Parent:Destroy()
end)

https://gyazo.com/833ab2149017f9cd6afeca324eb9e4ec

It only reacts when it touches my character

1 Like

Well touched only reacts when an unanchored or moving part touches the target part

1 Like

oh, well how can I make it so when it touches anything it get destroyed?

1 Like

Sorry but I’m not sure how you could do that. But also an off topic question, how do you do it so it does code like colored? (I’m new to the forum)

1 Like

do you mean syntax highlighting?

1 Like

– --code here --
this what you mean?

1 Like

well what type of script is it? Can you send a picture of your hierarchy?

The script works perfectly for me

1 Like

thats it i put it in a separate script, it’s also a server script

2 Likes

I mean send me a picture of your explorer tab

1 Like

Here
image

It is in replicatedstorage so it will not show in the workspace.
put it in the workspace

Wdym it won’t show I parent it to the workspace when I clone it.

Quoting from the developer hub page:

The Touched event only fires when an unanchored part touches the part with the Touched event, which explains why it only fires when a player walks onto it.

In other words…

script.Parent.Touched:Connect(function(touched) -- Part with the Touched Thing
	print(touched) -- It Must be unanchored
end)
1 Like

Yeah, I figured that out but it still doesn’t solve my problem.