-
What do you want to achieve?
I want when player reset their character, the animation still play when attacking -
What is the issue?
the animation isnt playing and i can’t attack enemies after resets character -
What solutions have you tried so far?
I tried to userepeat 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