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

The animation of the tools won't play, but plays during testing In roblox studio, Why Is that?

Asked by 2 years ago

As the name says, I made a couple of tools that has there animations stop working but works when testing In roblox studio, an example Is a wooden sword that plays a slash animation, and while doing that It stuns users for a long time, more longer than the swords cooldown, letting you stun lock them, most of the scripts work, only the animation doesn't work (Like I made a sword that has a custom slash animation, and during the slash animation It damages players and NPCS, the damage script works, just not the animation during Ingame)

Wooden sword script:

local tool = script.Parent
local Debounce = false
local CanDamage = false
local Slash = tool.Slash
local AbilityDebounce = false
local Sounds = {
    Damage = tool.Damage,
    Woosh = tool.Woosh,
    CriticalHit = tool.CriticalHit
}

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

        local SlashAnimation = Humanoid:FindFirstChild("Animator"):LoadAnimation(Slash)
        SlashAnimation:Play()
        task.wait(2)
        Debounce = false
        CanDamage = false
    end
end)

tool.Handle.Touched:Connect(function(hit)
    local humanoid = hit.Parent:WaitForChild("Humanoid")
    if humanoid and CanDamage == true then
        local CriticalHitChance = math.random(1,20)

        if CriticalHitChance == 20 then
            CanDamage = false
            Sounds.CriticalHit:Play()
            humanoid:TakeDamage(30)
            humanoid.WalkSpeed = 0
            humanoid.JumpPower = 0
            task.wait(5)
            humanoid.WalkSpeed = 16
            humanoid.JumpPower = 50
        end
        if CriticalHitChance <= 20 then
            CanDamage = false
            Sounds.Damage:Play()
            humanoid:TakeDamage(10)
            humanoid.WalkSpeed = 0
            humanoid.JumpPower = 0
            task.wait(3)
            humanoid.WalkSpeed = 16
            humanoid.JumpPower = 50
        end
    end
end)

Answer this question