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

Sword not giving kills, as well of giving phases, also It shows no error In output (?)

Asked by 1 year ago

Hello!

I'm trying to get a sword that when you get a kill, a kill will be Inserted In the Kills IntValue, however, It does not add a kill, also when you reach a phase, like this example:

5 kills = Phase 1

Its suppose to speed up the player as well of playing a theme, just Its not adding the phase, It also appears to not show a error message In output

Script:

local Tool = script.Parent
local SoundFolder = Tool.Sounds
local SlashAttack
local KillsValue = Tool.Kills
local Boolens = {
    Debounce = false,
    CanDamage = false
}
local Animations = {
    EquipAnimation = Tool.EquipAnimation,
    Idle = Tool.Idle,
    Slash = Tool.Slash,
}

Tool.Equipped:Connect(function()
    SoundFolder.Unsheath:Play()
    local Humanoid = Tool.Parent.Humanoid

    local EquipAnimationTrack = Humanoid:FindFirstChild("Animator"):LoadAnimation(Animations.EquipAnimation)
    EquipAnimationTrack:Play()
    task.wait(0.30)
    local Idle = Humanoid:FindFirstChild("Animator"):LoadAnimation(Animations.Idle)
    Idle:Play()
    Tool.Unequipped:Connect(function()
        Idle:Stop()
    end)
end)

Tool.Activated:Connect(function()
    if not Boolens.Debounce then
        Boolens.Debounce = true
        Boolens.CanDamage = true
        SoundFolder.Slash:Play()
        print("The tool has been clicked")
        local Humanoid = Tool.Parent.Humanoid

        SlashAttack = Humanoid:FindFirstChild("Animator"):LoadAnimation(Animations.Slash)
        SlashAttack:Play()
        task.wait(0.5)
        Boolens.CanDamage = false
        wait(1)
        Boolens.Debounce = false
    end
end)

Tool.Handle.Touched:Connect(function(hit)
    local Player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
    if Player then
        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 Boolens.CanDamage == true then
                    Boolens.CanDamage = false
                    humanoid:TakeDamage(30)
                    if humanoid.Health == 0 then
                        SoundFolder["Kill Get"]:Play()
                        KillsValue.Value = KillsValue.Value + 1
                    end
                end
            end
        end
    else
        local NPCHumanoid = hit.Parent:WaitForChild("Humanoid")
        if NPCHumanoid and Boolens.CanDamage == true then
            Boolens.CanDamage = false
            NPCHumanoid:TakeDamage(30)
            if NPCHumanoid.Health == 0 then
                SoundFolder["Kill Get"]:Play()
                KillsValue.Value = KillsValue.Value + 1
            end
        end
    end
end)

2 answers

Log in to vote
1
Answered by
MattVSNNL 620 Moderation Voter
1 year ago
Edited 1 year ago

There's a function on Humanoid called Died, It happens when a player or NPC dies

local Tool = script.Parent
local SoundFolder = Tool.Sounds
local SlashAttack
local KillsValue = Tool.Kills
local Boolens = {
    Debounce = false,
    CanDamage = false
}
local Animations = {
    EquipAnimation = Tool.EquipAnimation,
    Idle = Tool.Idle,
    Slash = Tool.Slash,
}

local kills = 0

Tool.Equipped:Connect(function()
    SoundFolder.Unsheath:Play()
    local Humanoid = Tool.Parent.Humanoid

    local EquipAnimationTrack = Humanoid:FindFirstChild("Animator"):LoadAnimation(Animations.EquipAnimation)
    EquipAnimationTrack:Play()
    task.wait(0.30)
    local Idle = Humanoid:FindFirstChild("Animator"):LoadAnimation(Animations.Idle)
    Idle:Play()
    Tool.Unequipped:Connect(function()
        Idle:Stop()
    end)
end)

Tool.Activated:Connect(function()
    if not Boolens.Debounce then
        Boolens.Debounce = true
        Boolens.CanDamage = true
        SoundFolder.Slash:Play()
        print("The tool has been clicked")
        local Humanoid = Tool.Parent.Humanoid

        SlashAttack = Humanoid:FindFirstChild("Animator"):LoadAnimation(Animations.Slash)
        SlashAttack:Play()
        task.wait(0.5)
        Boolens.CanDamage = false
        wait(1)
        Boolens.Debounce = false
    end
end)

Tool.Handle.Touched:Connect(function(hit)
    local Player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
    if Player then
        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 Boolens.CanDamage == true then
                    Boolens.CanDamage = false
                    humanoid:TakeDamage(30)
                    humanoid.Died:Connect(function()
                        SoundFolder["Kill Get"]:Play()
                        KillsValue.Value += 1
                        kills += 1

                        if kills >= 5 then

                            kills = 0

                            player1.Character:FindFirstChild("Humanoid").WalkSpeed = 24

                        end

                    end)
                end
            end
        end
    else
        local NPCHumanoid = hit.Parent:WaitForChild("Humanoid")
        if NPCHumanoid and Boolens.CanDamage == true then
            Boolens.CanDamage = false
            NPCHumanoid:TakeDamage(30)
            NPCHumanoid.Died:Connect(function()
                SoundFolder["Kill Get"]:Play()
                KillsValue.Value += 1
                kills += 1

            end)
        end
    end
end)
0
Small note: instead of KillsValue.Value = KillsValue.Value + 1 he/she can just do KillsValue += 1 Sabailuridze 126 — 1y
0
Yea MattVSNNL 620 — 1y
0
Its giving kills, just not adding the phases, also there Is a script Inside a IntValue imnotaguest1121 362 — 1y
0
Wdym not in the phases MattVSNNL 620 — 1y
View all comments (4 more)
0
Basically when you reach lets say 5 kills, you get a speed boost imnotaguest1121 362 — 1y
0
Oh sorry edited MattVSNNL 620 — 1y
0
Thanks! imnotaguest1121 362 — 1y
0
Np MattVSNNL 620 — 1y
Ad
Log in to vote
0
Answered by
enes223 327 Moderation Voter
1 year ago

hey you! have you ever heard of enes? if you are in trouble, better call enes!

Answer this question