Help on making a damage script not affect a certain player

I’m trying to make a damage script I whipped up not damage a certain player, how do i acheive this, code below.
It finds the player who hits its humanoid, how do I intercept it by checking if the player that hit it is the player that shouldnt hit it, I know about the return function, I just dont know how to set this up.

	local human = hit.Parent:findFirstChild("Humanoid")
        if (human ~= nil) then
		human.Health = human.Health - math.huge -- Change the amount to change the damage.
		wait(0.1)
		human:Destroy()
        end
end
script.Parent.Touched:connect(onTouched)
2 Likes

You would have to add something like

if [WayYouFindPleyrHere] then return end
else
—rest of the code

No, but I don’t know how to exactly find who hit it.

Wait I don’t get what you mean? Could you explain better please?

	if hit.Parent:findFirstChild("Humanoid").Parent.Name ==  "Player" then
		return
	end
	local human = hit.Parent:findFirstChild("Humanoid")
        if (human ~= nil) then
		human.Health = human.Health - math.huge -- Change the amount to change the damage.
		wait(0.1)
		human:Destroy()
        end
end
script.Parent.Touched:connect(onTouched)

figured it out on my own, leaving this for someone with the same issue in the future

Sorry, but I don’t get what you were trying to do still? I see taht your scripts checks if the hit part has a humanoid in it, but after if it hasn’t you make a variable for the humanoid? It doesn’t make sense to me sorry

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.