My drinking animation isn't working?

Hello, for some reason my drinking animation isn’t working whenever I left click. Am I suppose to put an event for a left click or is this ok. Any help will be appreciated.

local Cup = script.Parent
local Animation = Cup.Animation

Cup.Activated:Connect(function()
local Character = Cup.Parent
local Humanoid = Character.Humanoid

local AnimationTrack = Humanoid:LoadAnimation(Animation)
AnimationTrack:Play()

end)

1 Like

Hello, I assume you are using LocalScript placed inside tool.

-- LocalScript placed inside the tool
local LocalPlayer = game:GetService("Players").LocalPlayer
local Cup = script.Parent
local Animation = Cup.Animation
local isDrinking = false

Cup.Activated:Connect(function()
   if isDrinking then return end
   isDrinking = true
   local Character = Cup.Parent
   local Humanoid = LocalPlayer.Character.Humanoid
   local AnimationTrack = Humanoid:LoadAnimation(Animation)
   AnimationTrack:Play()
   AnimationTrack.Stopped:Wait()
   isDrinking = false
end)

Basically, Tool.Activated fires when player left clicks while equipping tool, so there’s no need concern for this. Maybe, you might want to attach photo of your explorer ancestry.

1 Like

Thank you for your response, but heres what comes out of the output
15:00:56.389 - Players.fonmin123.Backpack.Cup.drinkscript:10: attempt to index nil with ‘Character’

Sorry for the mistake, your error has occurred since I’ve declared LocalPlayer variable before the tool got parented to player.

This should work:

local Cup = script.Parent
local Animation = Cup.Animation
local isDrinking = false

Cup.Activated:Connect(function()
   if isDrinking then return end
   local LocalPlayer = game:GetService("Players").LocalPlayer
   isDrinking = true
   local Character = Cup.Parent
   local Humanoid = LocalPlayer.Character.Humanoid
   local AnimationTrack = Humanoid:LoadAnimation(Animation)
   AnimationTrack:Play()
   AnimationTrack.Stopped:Wait()
   isDrinking = false
end)
1 Like

Thank you for all of the help you have offered me. Really appreciated by me. :slight_smile:

And also for some reason it keeps telling me attempt to index nil with character. Idk why.

Nvm, I had to put it in a local script, no errors in the output, but the animation won’t play?

Did you enable RequiresHandleand added part named 'Handle' as a child of your cup tool?
Tool.Activated only fires when you have those two above done.

Or, does the place owner owns the animation? Unless the place owner owns the animation, it won’t play.

1 Like

Yes, I did checkmark Requires Hand, and there is a part called Handle.

I just did test on my studio, and it seems to be working fine.

Could you confirm this as well?

1 Like

It is a group game, but I am not the owner of the group is that why it will not work?

Exactly it is! Try asking group owner to upload animation, you can see this post for detail.

When submitting the animation do I tell my friend to put creator: me, or creator: (group name) does it matter?

The animation must be uploaded to the group.

If the game is group game, I suggest you to put creator as group.

Well, the animation doesn’t play, but atleast there are no errors in the output so idk, again…

Okay, here’s your checklist:

  • Put script in LocalScript
  • Make sure script is parented directly to Tool
  • Make sure RequiresHandle is enabled
  • Make sure Handle is parented directly to Tool
  • Make sure Animation is uploaded as creator Group
  • Set AnimationId with id of animation which is uploaded as creator Group
  • If animation is made for R6, make sure game to have default avatar to R6.

And it would be helpful if you attach link of the uploaded animation.

I have done all of those, but still to no avail, and here’s the link Drink - Roblox

Is the game uploaded to the group? Or is it uploaded to the account of the group’s owner

The game is uploaded to the group.