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

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

Asked by 2 years ago

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

Log in to vote
0
Answered by 2 years ago

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)
0
still dosnt work i tried putting a print and it prints i suppose theres somthing wrong wirth the animation Boyuanbogosess 17 — 2y
Ad
Log in to vote
0
Answered by 2 years ago

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

Answer this question