Issue animation

local RunService = game:GetService("RunService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Tool = script.Parent
local enabled = true


local drinkAnim = Tool:WaitForChild("drinkAnim")
local takeAnim = Tool:WaitForChild("takeAnim")
local holdAnim = Tool:WaitForChild("holdAnim")
local resetAnim = Tool:FindFirstChild("resetAnim")


local function purgeRightGrip(character)
	for _, obj in ipairs(character:GetDescendants()) do
		if obj:IsA("Weld") or obj:IsA("Motor6D") then
			if obj.Name == "RightGrip" or obj.Name:find("Grip") then
				obj:Destroy()
			end
		end
	end
end


local function stopAnimations(humanoid)
	for _, track in pairs(humanoid:GetPlayingAnimationTracks()) do
		if track.Animation == takeAnim or track.Animation == drinkAnim or track.Animation == holdAnim or track.Animation == resetAnim then
			track:Stop()
		end
	end
end

function onActivated()
	if not enabled then return end
	enabled = false

	local character = Tool.Parent
	local humanoid = character:FindFirstChildOfClass("Humanoid")
	if not humanoid then return end

	stopAnimations(humanoid)

	local drinkTrack = humanoid:LoadAnimation(drinkAnim)
	drinkTrack.Looped = false
	drinkTrack:Play()

	local playedSound = false
	local connection
	connection = RunService.Heartbeat:Connect(function()
		if drinkTrack and drinkTrack.IsPlaying and not playedSound and drinkTrack.TimePosition >= 1.7 then
			local handle = Tool:FindFirstChild("Handle")
			if handle and handle:FindFirstChild("DrinkSound") then
				handle.DrinkSound:Play()
			end
			playedSound = true
			connection:Disconnect()
		end
	end)

	task.wait(3)

	local boostEvent = ReplicatedStorage:FindFirstChild("ActivateBoost")
	if boostEvent then
		boostEvent:FireServer()
	end

	purgeRightGrip(character)

	Tool.Parent = nil
	task.delay(0.1, function()
		stopAnimations(humanoid)
		if resetAnim then
			local resetTrack = humanoid:LoadAnimation(resetAnim)
			resetTrack.Looped = false
			resetTrack:Play()
		end
		Tool:Destroy()
	end)
end

function onEquipped()
	local character = Tool.Parent
	local humanoid = character:FindFirstChildOfClass("Humanoid")
	if humanoid then
		local takeTrack = humanoid:LoadAnimation(takeAnim)
		takeTrack.Looped = false
		takeTrack:Play()

		task.delay(0.4, function()
			local holdTrack = humanoid:LoadAnimation(holdAnim)
			holdTrack.Looped = true
			holdTrack:Play()
		end)
	end

	local handle = Tool:FindFirstChild("Handle")
	if handle and handle:FindFirstChild("OpenSound") then
		handle.OpenSound:Play()
	end
end

function onUnequipped()
	local character = Tool.Parent
	local humanoid = character and character:FindFirstChildOfClass("Humanoid")
	if humanoid then
		
		stopAnimations(humanoid)

		
		purgeRightGrip(character)

		
		if resetAnim then
			local resetTrack = humanoid:LoadAnimation(resetAnim)
			resetTrack.Looped = false
			resetTrack:Play()
		else
			
			local drinkTrack = humanoid:LoadAnimation(drinkAnim)
			drinkTrack:Play()
			drinkTrack:Stop()
		end
	end
end


Tool.Activated:Connect(onActivated)
Tool.Equipped:Connect(onEquipped)
Tool.Unequipped:Connect(onUnequipped)

And here is a video

1 Like