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()
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.
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)