I been struggling to fix this bug where, when someone equips a tool with an animation, it sometimes plays the animation for everyone.
Code:
local tool = script.Parent
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local EquippedValue = tool.EquipValue
local Bound = 1
local IdleAnim = character.Humanoid:LoadAnimation(script.IdleAnim)
local DrinkAnim = character.Humanoid:LoadAnimation(script.EatAnim)
local OpenSound = tool.Handle.OpenSound
local DrinkSound = tool.Handle.DrinkSound
tool.Equipped:Connect(function()
EquippedValue.Value = true
OpenSound:Play()
IdleAnim:Play()
end)
tool.Unequipped:Connect(function()
EquippedValue.Value = false
Bound = 1
DrinkAnim:Stop()
DrinkSound:Stop()
OpenSound:Stop()
IdleAnim:Stop()
end)
tool.Activated:Connect(function()
if EquippedValue.Value == true and character.Attacking.Value == false and character.Dead.Value == false and character.Finished.Value == false and character.Finisher.Value == false and Bound == 1 then
Bound = 2
DrinkAnim:Play()
DrinkSound:Play()
script.Amount.Value = script.Amount.Value + 1
task.wait(2)
Bound = 1
end
end)
while task.wait() do
if script.Amount.Value == script.Limit.Value then
Bound = 0
task.wait(1.5)
DrinkAnim:Stop()
DrinkSound:Stop()
OpenSound:Stop()
IdleAnim:Stop()
tool:Destroy()
end
end
i think this cause by cloning the tool, because sometimes the cloned tool destroy itself.
