I want the tool to play an animation once clicked, help?
local Tool = script.Parent; enabled = true function onActivated(player) if not enabled then return end enabled = false local animation = player:FindFirstChild("Humanoid") local rawr = Tool:FindFirstChild("DrinkAnimation") animation:LoadAnimation(rawr) Tool.Handle.DrinkSound:Play() enabled = true end function onEquipped() print("Equipped") end script.Parent.Activated:connect(onActivated) script.Parent.Equipped:connect(onEquipped)
error: attempt to index local 'player' (a nil value) any way to make this work?
Activated event of Tool doesn't pass the Player as argument. What you need to do is access local player on start of your code.
wait(0.1) -- This is a good convention to make sure client variables have loaded local player = game.Players.LocalPlayer
Then, use that player variable instead.
The second problem is that you are only loading the animation. What :LoadAnimation does, it creates an AnimationTrack which you need to play.
local rawrAnim = animation:LoadAnimation(rawr) rawrAnim:Play()
Hope this helped.