Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How would I make sure thats its an npc not a player?

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?

2 answers

✓ Accepted answer

: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)

3 comments

1

line 2 is an error. if respawn = nil then what's wrong with this firewolf? Not to mention, :findFirstChild() is deprecated, and :FindFirstChild() should be used instead. same goes for :connect(), it should be :Connect()

0

Make sure to have double equal to sign.

0

i just copied and pasted his script, and then just edited it.

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

2 comments

0

sorry, didnt see this untill right now, it does work.

0

sorry, didnt see this untill right now, it does work.

This discussion is preserved as it was. New answers, comments, and votes are closed.