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
01grandFireball.Touched:Connect(function(Touched)
02    if Touched.Parent.Name ~= player.Name then
03    local Humanoid
04    if Touched.Parent:IsA("Accessory")then
05        Humanoid = Touched.Parent.Parent.Humanoid
06    elseif Touched.Parent:IsA("Model")then
07        Humanoid = Touched.Parent.Humanoid
08    end
09    if Humanoid ~= nil then
10            Humanoid:TakeDamage(5)
11            grandFireball:Destroy()
12        end
13    end
14end)

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

1Touched.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:

1grandFireball.Touched:Connect(function(Touched)
2    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:

1/Workspace -- Descendant of game and also child of game
2    /Part -- Descendant of Workspace and game
3        /AnotherPart -- Descendant of Workspace, Part and game
4/ReplicatedStorage -- Descendant and also child of game
5    /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