Slash 2 animation and equip animation is not playing but slash 1 animation is perfectly working how can i fix that?
local WeaponTool = script.Parent.Parent.Parent
local char = game.Players.LocalPlayer.CharacterAdded:Wait()
local randomSlash = 1
WeaponTool.Equipped:Connect(function()
game.ReplicatedStorage.ConnectM6D:FireServer(WeaponTool.PathmakerModel.BodyAttach)
char.Torso.ToolGrip.Part0 = char.Torso
char.Torso.ToolGrip.Part1 = WeaponTool.PathmakerModel.BodyAttach
char.Humanoid:LoadAnimation(script.Equip):Play()
wait(2)
char.Humanoid:LoadAnimation(script.idle):Play()
end)
WeaponTool.Activated:Connect(function()
if WeaponTool.Activated then
if randomSlash == 1 then
char.Humanoid:LoadAnimation(script.idle):Stop()
char.Humanoid:LoadAnimation(script.Attack1):Play()
char.Humanoid:LoadAnimation(script.idle):Play()
randomSlash +=1
end
if randomSlash == 2 then
char.Humanoid:LoadAnimation(script.idle):Stop()
char.Humanoid:LoadAnimation(script.Attack2):Play()
char.Humanoid:LoadAnimation(script.idle):Play()
randomSlash = randomSlash - 1
end
end
WeaponTool.Unequipped:Connect(function()
game.ReplicatedStorage.DisconnectM6D:FireServer()
end)
end)
You need to make use of elseif rather than two if statements.
Also, donāt worry about stopping the Idle animation before playing an Attack animation. It should automatically work. If not, you can set animation-priorities in the animation.
local plr = game:GetService("Players").LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
local IdleAnim = humanoid:LoadAnimation(script:WaitForChild("idle"))
local Attack1Anim = humanoid:LoadAnimation(script:WaitForChild("Attack1"))
local Attack2Anim = humanoid:LoadAnimation(script:WaitForChild("Attack2"))
WeaponTool.Activated:Connect(function()
if randomSlash == 1 then
char.Humanoid:LoadAnimation(script.Attack1):Play()
randomSlash +=1 --i suggest using math.Random()
elseif randomSlash == 2 then
char.Humanoid:LoadAnimation(script.Attack2):Play()
randomSlash = randomSlash - 1 --i suggest using math.Random()
end
end)
and if youāre planning on only using two attack anims, you can just make it say āelseā rather than āelseif randomSlash == 2ā so it doesnāt have to check that everyime.
Iām not familiar with the way you make the random-number so if this also doesnāt work I suggest using math.Random()
also, I advise loading the animations in the tool.Equipped function because sometimes it can cause an error. But thatās up to you since you might not have those errors.