Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Making a projectile not hurt the owner?

Asked by 6 years ago

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

Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

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)
0
The tool is part of the character, but the projectile is part of workspace. Edbotikx 99 — 6y
0
You could always parent the projectile to the character? LifeInDevelopment 364 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

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.

Answer this question