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

Made a crowbar that damages players, but won't damage teammates, but appears to not work?

Asked by 2 years ago

I made a crowbar that damages players however won't damages teammates but It appears to attempt with nil, I want It so when your not In a team you can damage everyone but If your not In a team you can damage players, but not your teammate

Script:

local tool = script.Parent
local Woosh = tool.Woosh
local PANSOUNDNOTCLICKBAIT = tool.PAN
local Slash = tool.Slash
local Debounce = false
local CanDamage = false

tool.Activated:Connect(function()
    if not Debounce then
        Woosh:Play()
        Debounce = true
        CanDamage = true
        local Hum = tool.Parent.Humanoid

        local AnimationTrack = Hum:LoadAnimation(Slash)
        AnimationTrack:Play()
        wait(0.9)
        CanDamage = false
        Debounce = false
    end
end)

tool.Handle.Touched:Connect(function(hit)
    local humanoid = hit.Parent:FindFirstChildWhichIsA("Humanoid")

    local player1 = game.Players:GetPlayerFromCharacter(hit.Parent)
    local player2 = game.Players:GetPlayerFromCharacter(tool.Parent)

    if player1.TeamColor ~= player2.TeamColor then
        if humanoid and CanDamage == true then
            humanoid:TakeDamage(10)
            CanDamage = false
            humanoid.PlatformStand = true
            wait(1)
            humanoid.PlatformStand = false
        end
    end
end)

1 answer

Log in to vote
1
Answered by 2 years ago
local tool = script.Parent
local Woosh = tool.Woosh
local PANSOUNDNOTCLICKBAIT = tool.PAN
local Slash = tool.Slash
local Debounce = false
local CanDamage = false

tool.Activated:Connect(function()
    if not Debounce then
        Woosh:Play()
        Debounce = true
        CanDamage = true
        local Hum = tool.Parent.Humanoid

        local AnimationTrack = Hum:WaitForChild("Animator"):LoadAnimation(Slash)
        AnimationTrack:Play()
        task.wait(0.9)
        CanDamage = false
        Debounce = false
    end
end)

tool.Handle.Touched:Connect(function(hit)
    local player1 = game.Players:GetPlayerFromCharacter(tool.Parent)
    local player2 = game.Players:GetPlayerFromCharacter(hit.Parent)

    if (player1 ~= nil) and (player2 ~= nil) then
        local humanoid = (player2.Character or player2.CharacterAdded:Wait()):FindFirstChildWhichIsA("Humanoid")

        if (player1.TeamColor ~= player2.TeamColor) then
            if (humanoid ~= nil) and CanDamage == true then
                humanoid:TakeDamage(10)
                CanDamage = false
                humanoid.PlatformStand = true
                task.wait(1)
                humanoid.PlatformStand = false
            end
        end
    end
end)
0
Yo thanks! I was just wondering how to modify It so It damages NPCS as well imnotaguest1121 362 — 2y
Ad

Answer this question