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

How to make my fireball script not damage the player who casts it?

Asked by 4 years ago

I have a local script and a script and a remote event for the fireball, I have no problems except I have no clue at all to make it so that the caster of the fireball doesn't get damaged by the fireball.

Script in ServerScriptService:

game:GetService("ReplicatedStorage").RemoteEvent.OnServerEvent:Connect(function(plr)

    local fireball = game:GetService("Lighting").FireBending.Fire1
    local char = plr.Character

    local fire = fireball:Clone()
    fire.Parent = workspace
    fire.CFrame = char.Humanoid.Torso.CFrame * CFrame.new(0,0,-10)

    local bodyv = Instance.new("BodyVelocity")
    bodyv.MaxForce = Vector3.new(1e8,1e8,1e8)
    bodyv.Velocity = char.Humanoid.Torso.CFrame.lookVector * 150
    bodyv.Parent = fire

    local fireanim1 = char.Humanoid:LoadAnimation(script.FireAnim1)
    local fireanim2 = char.Humanoid:LoadAnimation(script.FireAnim2)
    local fireanim3 = char.Humanoid:LoadAnimation(script.FireAnim3)
    local choose = math.random(1,3)
    if choose == 1 then
        fireanim1:Play()
    elseif choose == 2 then
        fireanim2:Play()
    elseif choose == 3 then
        fireanim3:Play()
    end

    wait(2)
        fire:Destroy()
end)

And the LocalScript in the player's backpack:

local UserInputService = game:GetService("UserInputService")
local plr = game:GetService("Players").LocalPlayer
local mouse = plr:GetMouse()
local char = plr.Character or plr.CharacterAdded:wait()
local fireball = game:GetService("Lighting"):WaitForChild("FireBending").Fire1
local canattack = true
local checkdeath = true

UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
    if input.KeyCode == Enum.KeyCode.Z and canattack == true and not gameProcessedEvent then
        game:GetService("ReplicatedStorage").RemoteEvent:FireServer()
        canattack = false
        wait(3)
        canattack = true
    end
end)
0
Spawn the fireball a little farther away from player? lukeh990 23 — 4y
1
So basically, just check if the parent name of the hit is not the player's name. alexfinger21 341 — 4y
2
when spawning the fireball, add a stringvalue under the fireball that lists the player who cast it as its value, the damage script should then check that the person it touched doesn't have a name matching the tag SerpentineKing 3885 — 4y

1 answer

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

You can use :IsDescendantOf() to check if a part is a descendant of another. We can have the fireball check if the part it hits is not a descendant of the character who created the fireball, and if so, damage them.

fire.Touched:Connect(function(Hit)
    if hit.Parent:FindFirstChild("Humanoid") then --check if the hit part is part of a player or NPC
        if not Hit:IsDescendantOf(character) then --checks if the hit part is NOT a descendant of the character
            --Code here
        end
    end
end)
0
I think you mean ":IsAncestorOf()". youtubemasterWOW 2741 — 4y
0
An ancester is like a parent of a parent, a descendant is like a child of a child, we check if the hit is a child or child of child of the character model. virushunter9 943 — 4y
0
Oh yeah, I forgot. Sorry about that. youtubemasterWOW 2741 — 4y
Ad

Answer this question