Connections and how to change the script

  1. What I want to achieve? Equipping fist plays the animation, but unequipping would stop the animations

  2. What is the issue? If you quickly equip/unequip sometimes the animation does not stop (I know why, cus of wait and that it plays after it tries to stop it, but how do I not let it play, in a more optimised way… I tried connections but it just deletes (as I understood) the “equipped” event)

local RS = game:GetService('ReplicatedStorage')
local Players = game:GetService('Players')
local Debris = game:GetService('Debris')
local tool = script.Parent
local character = tool.Parent.Parent.Character
local HRP = character:WaitForChild('HumanoidRootPart')
local Humanoid = character:WaitForChild('Humanoid')
local Animator = Humanoid:WaitForChild('Animator')
local Player = Players:GetPlayerFromCharacter(character)

local animations = {
	['Equip'] = Animator:LoadAnimation(RS.Animations.Fist1.FistEquip);
	['FistHit1'] = Animator:LoadAnimation(RS.Animations.Fist1.FistHit1);
	['FistIdle'] = Animator:LoadAnimation(RS.Animations.Fist1.FistIdle);
}

local Equipped = false

local connection

connection = tool.Equipped:Connect(function()
	if Humanoid:GetAttribute('Stunned') == 0 then
		Equipped = true
		animations['Equip']:Play(0, 12)
		local FistEquipSFX = RS.Sounds.Fist.FistEquip:Clone()
		FistEquipSFX.Parent = character
		FistEquipSFX:Play()
		Debris:AddItem(FistEquipSFX, FistEquipSFX.TimeLength)
		wait(0.3)
		animations['FistIdle']:Play(0, 12)
	else
		Humanoid:UnequipTools()
	end
end)

tool.Unequipped:Connect(function()
	Equipped = false
	--soundplay
	connection:Disconnect()
	animations['Equip']:Stop()
	animations['FistIdle']:Stop()
end)

tool.Activated:Connect(function()
	if Humanoid:GetAttribute('Stunned') == 0 and Equipped == true then
		print('trying okay')
		animations['FistHit1']:Play(0, 14, 1)
		--soundplay
	end
end)

Oh and also, I don’t really understand how weight of animation works… i.e: Here if you try to M1 it won’t play FistHit1, even tho it prints “trying okay”

Found out the issue months ago, learn about animation priorities.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.