function onTouched(hit) if hit.Parent:findFirstChild("Humanoid") and hit.Parent:findFirstChild("Respawn") = nil then hit.Parent.Humanoid:TakeDamage(.5) end end script.Parent.Touched:connect(onTouched)
How would I make sure thats its a npc? Well, the player doesn't have a script named "Respawn" in it, but my npc does. so how would I use the :findFirstChild() function, but make sure that it respawns as nil, not a actually find it. Is there an other function?
:GetPlayerFromCharacter
is a great way to see if a character is a player, in your case, we can just do the opposite by checking if it didn't return the player or true.
I'm using another if statement just to make the line not as long and make it less confusing.
function onTouched(hit) if hit.Parent:findFirstChild("Humanoid") and hit.Parent:findFirstChild("Respawn") = nil then if not game.Players:GetPlayerFromCharacter(hit.Parent) then hit.Parent.Humanoid:TakeDamage(.5) end end end script.Parent.Touched:connect(onTouched)
Easy solution all you have to do is check if they are in the Players service.
function onTouched(hit) if hit.Parent:findFirstChild("Humanoid") and hit.Parent:findFirstChild("Respawn") = nil then if game.Players:FindFirstChild(hit.Parent.Name) then hit.Parent.Humanoid:TakeDamage(.5) end end end script.Parent.Touched:connect(onTouched)
Good luck! Remember to accept if this works