I’m trying to make a combat system which displays a different animation each time the mouse 1 button is pressed but after the player dies it displays this error and the script stops working
this is the script -
local combat = script.Parent
local remote = game.ReplicatedStorage:WaitForChild("M1_Remote")
local currentCombo = 0
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local isStunned = char:WaitForChild("isStunned")
local isBlocking = char:WaitForChild("isBlocking")
local currentlyUsingMove = char:WaitForChild("currentlyUsingMove")
local m1isOnCD = false
local prevWalkSpeed = hum.WalkSpeed
combat.Activated:Connect(function()
if isBlocking.Value == false and isStunned.Value == false and currentlyUsingMove.Value == false then
if m1isOnCD == false then
if currentCombo == 0 then
local m1Anim = Instance.new("Animation")
m1Anim.AnimationId = "rbxassetid://12282915044"
local animTrack = hum:LoadAnimation(m1Anim)
animTrack:Play()
remote:FireServer(currentCombo)
currentCombo = 1
hum.WalkSpeed = 2
task.wait(1.5)
hum.WalkSpeed = prevWalkSpeed
task.spawn(function()
currentlyUsingMove.Value = true
task.wait(0.5)
currentlyUsingMove.Value = false
end)
elseif currentCombo == 1 then
local m12anim = Instance.new("Animation")
m12anim.AnimationId = "rbxassetid://12283112114"
local animtrack = hum:LoadAnimation(m12anim)
animtrack:Play()
remote:FireServer(currentCombo)
currentCombo = 2
task.spawn(function()
currentlyUsingMove.Value = true
task.wait(0.5)
currentlyUsingMove.Value = false
end)
hum.WalkSpeed = 2
task.wait(1.5)
hum.WalkSpeed = prevWalkSpeed
elseif currentCombo == 2 then
local m13rdanim = Instance.new("Animation")
m13rdanim.AnimationId = "rbxassetid://12283156070"
local animTrack = hum:LoadAnimation(m13rdanim)
animTrack:Play()
remote:FireServer(currentCombo)
currentCombo = 0
task.spawn(function()
currentlyUsingMove.Value = true
task.wait(0.5)
currentlyUsingMove.Value = false
end)
task.spawn(function()
hum.WalkSpeed = 2
task.wait(1.5)
hum.WalkSpeed = prevWalkSpeed
end)
m1isOnCD = true
task.wait(2.5)
m1isOnCD = false
end
end
end
end)