Animation doesn't play and cannot attack after reset

  1. What do you want to achieve?
    I want when player reset their character, the animation still play when attacking

  2. What is the issue?
    the animation isnt playing and i can’t attack enemies after resets character

  3. What solutions have you tried so far?
    I tried to use repeat wait() until stuffs but still doesn’t work

Here’s the code

local players = game:GetService("Players")

--References
local Tool = script.Parent
local Handle = Tool:WaitForChild("Handle")
local player = game.Players.LocalPlayer 
local character = player.Character or player.CharacterAdded:Wait()

while character.Parent == nil do
	character.AncestryChanged:Wait()
end

local humanoid = character:WaitForChild("Humanoid")

repeat wait(1) until humanoid
repeat wait(1) until player.Character
repeat wait(1) until Tool.Parent:FindFirstChild("Humanoid")

--Events
local swordHandler = script.Parent:WaitForChild("SwordHandler")

--Animations
local AttackAnim1 = humanoid:LoadAnimation(script:WaitForChild("OneSwingAnimation"))
local AttackAnim2 = humanoid:LoadAnimation(script:WaitForChild("TwoSwingAnimation"))
local AttackAnim3 = humanoid:LoadAnimation(script:WaitForChild("SpinAnimation"))

--Sound
local SlashSound = Handle:WaitForChild("Swoosh")
local LungeSound = Handle:WaitForChild("Clang")
local StabSound = Handle:WaitForChild("Stab")
--Variables
local click = 0
local lastClick = 0
local TimeBetween = 0.4
local debounce = false

Tool.Activated:Connect(function(isTyping)
	if isTyping then return end
	if humanoid.Health == 0 then return end
	
	if not debounce then
		debounce = true
		
		click += 1
		
		if click >= 3 then
			swordHandler:FireServer(true)
			AttackAnim3:Play()
			SlashSound:Play()
			click = 0
		elseif click == 1 then
			swordHandler:FireServer(false)
			AttackAnim2:Play()
			SlashSound:Play()
		elseif click == 2 then
			swordHandler:FireServer(false)
			AttackAnim1:Play()
			wait(0.2)
			SlashSound:Play()
		end
		
		wait(TimeBetween)
		debounce = false
		
		wait(0.1)
		lastClick = click
	end
end)

while true do
	wait(5)
	if lastClick == click then
		click, lastClick = 0,0
	end
end

1 Like

Please may you eplain in more detail the issue, animations don’t play after you reset? Or the script doesn’t work after you reset?

Both of them doesn’t work out after resets character

Try placing the script inside the StarterCharacterScripts folder.

local players = game:GetService("Players")
--References
local Tool = script.Parent
local Handle = Tool:WaitForChild("Handle")
local player = players.LocalPlayer or players.PlayerAdded:wait()
local character = player.Character or player.CharacterAdded:wait()
local humanoid = character:WaitForChild("Humanoid")

--Events
local swordHandler = script.Parent:WaitForChild("SwordHandler")
--Animations
local AttackAnim1 = humanoid:LoadAnimation(script:WaitForChild("OneSwingAnimation"))
local AttackAnim2 = humanoid:LoadAnimation(script:WaitForChild("TwoSwingAnimation"))
local AttackAnim3 = humanoid:LoadAnimation(script:WaitForChild("SpinAnimation"))
--Sound
local SlashSound = Handle:WaitForChild("Swoosh")
local LungeSound = Handle:WaitForChild("Clang")
local StabSound = Handle:WaitForChild("Stab")
--Variables
local click = 0
local lastClick = 0
local TimeBetween = 0.4
local debounce = false

Tool.Activated:Connect(function(isTyping)
	if isTyping then return end
	if humanoid.Health <= 0 then return end
	if not debounce then
		debounce = true
		click += 1
		if click >= 3 then
			swordHandler:FireServer(true)
			AttackAnim3:Play()
			SlashSound:Play()
			click = 0
		elseif click == 1 then
			swordHandler:FireServer(false)
			AttackAnim2:Play()
			SlashSound:Play()
		elseif click == 2 then
			swordHandler:FireServer(false)
			AttackAnim1:Play()
			wait(0.2)
			SlashSound:Play()
		end
		task.wait(TimeBetween)
		debounce = false
		lastClick = click
	end
end)

while task.wait(5) do
	if lastClick == click then
		click, lastClick = 0, 0
	end
end

I put the tool inside the startercharacterscripts and it worked. Thank you very much sir! :wink: