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

Animation runs on studio but not on the actual game?

Asked by 4 years ago

The title shows my issue, any help would be great, thanks!

Mouse.Button1Up:Connect(function()
    if not AnimationDebounce then
        if game.Players.LocalPlayer.Character:FindFirstChildOfClass("Tool") and script.Parent.BoolValue.Value == true and Equip == true then
            if script.Parent:FindFirstChild("SelectionBox") then
                script.Parent.SelectionBox:Destroy()
            end
            local Tool = script.Parent
            if Tool.Parent == game.Players.LocalPlayer.Character then
            if Tool:FindFirstChild("DrinkPart") then
            AnimationDebounce = true
            if game.Players.LocalPlayer.Character:FindFirstChild("Torso") then
                        if Equip == true then
                            script.Parent.RemoteEvent:FireServer()
                            Animation:Play()
                wait(3)
                            AnimationDebounce = false
                            end
                end
                end
                end
        end
    end
end)

1 answer

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

If the animations weren't made by you or Roblox, they will not show up. But the reason this is not working is because the code you're using is highly inefficient.

Add a bool value inside of the tool called "cooldown" and set the value to false.

Possible fix:

local tool = script.Parent
local animation = script.Animation
local cooldown = script.Parent.Cooldown

tool.Equipped:Connect(function()
        wait(1) -- Waits to prevent lag
    local humanoid = tool.Parent:FindFirstChildWhichIsA('Humanoid')
    if humanoid and cooldown == false then
        cooldown = true
        local playanim = humanoid:LoadAnimation(animation)
        playanim:Play()
        tool.Handle.Damage.Disabled = false
        wait(0.7)
        playanim:Stop()
        tool.Handle.Damage.Disabled = true
        wait(0.5)
        cooldown = false
    end
end)
Ad

Answer this question