Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Animation runs on studio but not on the actual game?

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

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.