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

How do I make it not damage the player who casted it?

Asked by
LL0YD01 17
4 years ago
    grandFireball.Touched:Connect(function(Touched)
        if Touched.Parent.Name ~= player.Name then
        local Humanoid
        if Touched.Parent:IsA("Accessory")then
            Humanoid = Touched.Parent.Parent.Humanoid
        elseif Touched.Parent:IsA("Model")then
            Humanoid = Touched.Parent.Humanoid
        end
        if Humanoid ~= nil then
                Humanoid:TakeDamage(5)
                grandFireball:Destroy()
            end
        end
    end)

The script works and damages the dummies however I was testing and to see if it would damage me and it does and I do not want that happening.

1 answer

Log in to vote
1
Answered by
imKirda 4491 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

The possible reason why is because you are checking if

Touched.Parent.Name ~= player.Name

In this case you except Touched to be part which is children of the character, but the thing is that characters also have Accessories which have handles in them, handles also have hitbox but they are not parent of character, they are parent of the accessory and descendant of character. So to fix this, what you could do is:

grandFireball.Touched:Connect(function(Touched)
    if not Touched:IsDescendantOf(player.Character) then

What this does is that it checks if the hit is descendant of player's character. basically descendants in roblox are parts that are located in some object, by that i mean:

/Workspace -- Descendant of game and also child of game
    /Part -- Descendant of Workspace and game
        /AnotherPart -- Descendant of Workspace, Part and game
/ReplicatedStorage -- Descendant and also child of game
    /Folder -- Descendant of ReplicatedStorage and game but not descendant of Workspace
0
Ah okay LL0YD01 17 — 4y
0
Please accept the answer @LL0YD01 Optikk 499 — 4y
Ad

Answer this question