Really basic script not working

so um I have this basic script here and I don’t know why it won’t work. I don’t know if its lag or something but yeah.

Script is in part:

script.Parent.Touched:Connect(function()
	local h = script.Parent.Parent:FindFirstChild("Humanoid")
	if h then
		print("working!")
	end
end)
1 Like
script.Parent.Touched:Connect(function(hit)
	local h = hit.Parent:FindFirstChild("Humanoid")
	if h then
		print("working!")
	end
end)
1 Like

still not working :frowning: (characters)

What the output says? Is there any error?

What are you trying to achieve? It just seems like your current code only checks whether or not the parent of the parent of the script finds a humanoid.

1 Like

there isnt any error. it’s not printing anything

What do you mean that? Can you tell me what are you trying to do?

try this? also are you sure you are running this in a server script.

script.Parent.Touched:Connect(function(hit)
	local h = hit.Parent:FindFirstChild("Humanoid")
	if h ~= nil then
		print("working!")
	end
end)

Does the part have canTouch enabled?

There’s a few things I’m noting as I read this script.

I assume you’re putting this in a part, and wish to detect if a player’s character touched it.

Try this:

script.Parent.Touched:Connect(function(o)
	local model = o:FindFirstAncestorWhichIsA("Model")
	if model and model:FindFirstChild("Humanoid",true) then
		print("working!")
	end
end)

Yes. the script is in the part and not a local script

Still not working…Thanks for the help though.

Hmm, should have… I use this script… Make sure the parts of the model have “CanTouch” property checked.

It is…I’m trying a new part right now
EDIT: Didnt work

Yeah i’ve tested this in a new place, even have collisions off… it works. Script is under the part.

Hmmm if its a lot of parts (model), may want to do this differently… maybe have a large invisible box in the model, that’s welded, and has the script running under it.

nope…

Could you also screenshot the script please?

script.Parent.Touched:Connect(function(HitObject)
	local h = HitObject:FindFirstAncestorOfClass("Model"):FindFirstChild("Hmanoid")

	if h then
		print("working!")
	end
end)

i turned off my caps lock after i pressed the i lol

1 Like