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

How do I make my damage script damage everyone else except me?

Hi, I have this damage script I made and it works, but it also damages my self.

script.Parent.Touched:connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid")~= nil then
    hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 25
        script.Parent:remove()
       		
	end
	
end)

How would I go about fixing this issue? Any help would be appreciated. -A newbie Scripter

1 answer

script.Parent.Touched:connect(function(hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if hit.Parent:FindFirstChild("Humanoid")~= nil and player.UserID ~= 00000 then
	 -- change 00000 with your id
    hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 25
        script.Parent:remove()
    end

end)
end)

3 comments

0

Stop using deprecated methods. it’s script.Parent:Destroy() and :Connect(), not :connect

0

They both work

0

@incap it really dont matter it works either way.

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