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

Why is my animation for my tool not playing when the player interacts it?

I have this tool that when you interact it is gonna play an animation. but for some reason the animation isn't playing. any help would be great! also, nothing has been printing in the output here is the code:

local Players = game:GetService("Players")
local character = Players.LocalPlayer.Character

if not character then
	character = Players.LocalPlayer.CharacterAdded:Wait()
end

local humanoid = character:WaitForChild("Humanoid")

local drinkAnim = Instance.new("Animation", character)

drinkAnim.Name = "DrinkAnim"
local drinkAnimID drinkAnim.AnimationId = "rbxassetid://10128937781"

local animTrack = humanoid:LoadAnimation(drinkAnim)

script.Parent.Handle.Drink.Triggered:Connect(function()
	script.Parent.Handle.Drink.Enabled = false
	animTrack:Play()
	script.Parent.Handle.DrinkSound:Play()
	wait(1)
	script.Parent:Destroy()
end)

2 answers

✓ Accepted answer

Try this:

local Players = game:GetService("Players")
local character = Players.LocalPlayer.Character or Players.LocalPlayer.CharacterAdded:Wait()

local humanoid = character:WaitForChild("Humanoid")

local drinkAnim = Instance.new("Animation", character)

drinkAnim.Name = "DrinkAnim"
local drinkAnimID drinkAnim.AnimationId = "rbxassetid://10128937781"

script.Parent.Handle.Drink.Triggered:Connect(function()
	local animTrack = humanoid:WaitForChild("Animator"):LoadAnimation(drinkAnim)
	animTrack.Priority = Enum.AnimationPriority.Action
	script.Parent.Handle.Drink.Enabled = false
	animTrack:Play()
	script.Parent.Handle.DrinkSound:Play()
	task.wait(1)
	script.Parent:Destroy()
end)

1 comment

0

still dosnt work i tried putting a print and it prints i suppose theres somthing wrong wirth the animation

Ok i figured out the problem, instead of a animation i used a decal Bruh.

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