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

Why Won't My Animation Play Consistently?

Asked by 4 years ago

So, I created an animation that is supposed to play globally while a certain key is held down (panting while holding 'r'). It usually works (meaning, everyone can see the animation and it repeats indefinitely until the key is released); however, sometimes it will simply stop doing the animation or only show it for the player that is holding 'r' (as if it was played locally). My relevant code is shown below. It is all within a local script (I thought this would make it play locally 100% of the time, but it frequently plays for everyone too, so I don't really think that's the problem).

m.KeyDown:connect(function(key)
    local player = game.Players.LocalPlayer
    if key == "r" and player.Character.Humanoid.WalkSpeed == 16 then -- Holding down 'R'
        game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
        player.Character.Humanoid:UnequipTools() -- unequips all equipped tools.
        for i, Tools in pairs(player.Backpack:GetChildren()) do
            if Tools:IsA("Tool") then
                Tools.Enabled = false
            end
        end
        local animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Panting)
        game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 0
        game.Players.LocalPlayer.Character.Humanoid.JumpPower = 0
        wait(.5) -- kinda a penalty for even deciding to rest, and keeps animation from glitching
        animation:Play()
        script.Parent.Stats.Frame.StaminaQuantity.StaminaRegen.Disabled = true
        script.Parent.Stats.Frame.StaminaQuantity.RestStaminaRegen.Disabled = false
    end
end)

If anyone has any idea why this is broken, I'd appreciate it so much. Thanks!

0
when exporting the animation there is an option to have it as a looped animation just check that Donut792 216 — 4y
0
I did. Sometimes it loops as it should. Other times, no. corncob567 275 — 4y
1
try a while loop on line 3 and once they stop holding r do animation:Stop() Donut792 216 — 4y

1 answer

Log in to vote
1
Answered by
Donut792 216 Moderation Voter
4 years ago
Edited 4 years ago

got this far and got bored and gave up but you might be able to salvage the script into something that works

local player = game.Players.LocalPlayer
local m = player:GetMouse()
local Human = player.Character:WaitForChild("Humanoid")
local animation = Human:LoadAnimation(script.Panting)
local bagdebounce = false
m.KeyDown:Connect(function(key)
    local player = game.Players.LocalPlayer
    if key == "r" and player.Character.Humanoid.WalkSpeed == 16 then
    repeat
    if bagdebounce == false then
        game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
        player.Character.Humanoid:UnequipTools()
        for i, Tools in pairs(player.Backpack:GetChildren()) do
            if Tools:IsA("Tool") then
                Tools.Enabled = false
            end
        end
    bagdebounce = true
    end
        Human.WalkSpeed = 0
        Human.JumpPower = 0
        wait(.5)
        animation:Play()
        --script.Parent.Stats.Frame.StaminaQuantity.StaminaRegen.Disabled = true
       -- script.Parent.Stats.Frame.StaminaQuantity.RestStaminaRegen.Disabled = false
    until key == not "r"
    end
bagdebounce = false
Human.WalkSpeed = 16
Human.JumpPower = 50
animation:Stop()
end)
Ad

Answer this question