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

Making a projectile not hurt the owner?

The part with the damage script in it is in Lighting. Using a script in a tool I clone it into workspace, but it hurts me, the person who cloned it. How can I make it not hurt whoever summoned the clone? I've tried all kinds of crazy things to no avail.

hurt = true
function touch(hit)
     if hurt == true then
	humanoid = hit.Parent:FindFirstChild("Humanoid")
    if humanoid then
	hit.Parent:FindFirstChild("Humanoid").Health = hit.Parent:FindFirstChild("Humanoid").Health -30
   hurt = false
   wait (0.1)
   hurt = true

end
end
end

script.Parent.Touched:connect(touch)

2 answers

Check if the tool isn't a descendant of the humanoid's parent (the character).

local tool = script.Parent

script.Parent.Touched:Connect(function(hitPart)
	if not tool:IsDescendantOf(hitPart.Parent) then
		-- ...
	end
end)

2 comments

0

The tool is part of the character, but the projectile is part of workspace.

0

You could always parent the projectile to the character?

I like to use StringValues to achieve this, but I'm sure there are probably better ways to do this.

So, whenever you clone the part with the damage script, insert a StringValue in there called 'Owner' or whatever you'd like, and set the value to the name of the person that you do not want to hurt.

Afterwards, in the projectile script, just add an if statement to check if the person who was hit is the value in the StringValue.

If you would like to see some example code, just ask.

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