How can i make it so the script keeps working after the player dies?
Everything else works except the animations after the players death
local uis = game:GetService("UserInputService")
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local M1 = hum:LoadAnimation(script.Animations.M1)
local M2 = hum:LoadAnimation(script.Animations.M2)
local M3 = hum:LoadAnimation(script.Animations.M3)
local combo = 1
local cooldown = false
local lastcooldown = false
uis.InputEnded:Connect(function(I,E)
if E then return end
if I.UserInputType == Enum.UserInputType.MouseButton1 then
if char:FindFirstChild("Stunned") then return end
if cooldown == true then return end
if lastcooldown == true then return end
spawn(function()
cooldown = true
script.Swing:Play()
task.wait(.65)
cooldown = false
end)
if combo == 3 then
game.ReplicatedStorage.MainEvent:FireServer("Last")
M3:Play()
spawn(function()
lastcooldown = true
task.wait(1.5)
lastcooldown = false
end)
spawn(function()
task.wait(.1)
combo = 1
end)
elseif combo == 2 then
game.ReplicatedStorage.MainEvent:FireServer("Regular")
M2:Play()
combo = combo + 1
elseif combo == 1 then
game.ReplicatedStorage.MainEvent:FireServer("Regular")
M1:Play()
combo = combo + 1
end
end
end)
this is the client side1
game.ReplicatedStorage.MainEvent.OnServerEvent:Connect(function(plr, Argument)
if Argument == "Regular" then
spawn(function()
plr.Character.Humanoid.WalkSpeed = 7
task.wait(.65)
plr.Character.Humanoid.WalkSpeed = 16
end)
task.wait(.25)
local hitbox = Instance.new("Part")
hitbox.Parent = workspace
hitbox.Shape = "Ball"
hitbox.CanCollide = false
hitbox.Anchored = true
hitbox.Size = Vector3.new(11,11,11)
hitbox.BrickColor = BrickColor.new("Really red")
hitbox.Transparency = 1 -- make it .5 for testing
hitbox.CFrame = plr.Character.HumanoidRootPart.CFrame * CFrame.new(0,0, -5)
game.Debris:AddItem(hitbox,1)
local BV2 = Instance.new("BodyVelocity")
BV2.MaxForce, BV2.Velocity = Vector3.new(5e4, 5e2, 5e4), plr.Character.HumanoidRootPart.CFrame.lookVector * 20
BV2.Parent = plr.Character.HumanoidRootPart
game.Debris:AddItem(BV2, 0.16)
local hitboxcooldown = false
hitbox.Touched:Connect(function(hit)
if hit.Parent.Name ~= plr.Name and hit.Parent:FindFirstChild("Humanoid") then
if hitboxcooldown == true then return end
hitboxcooldown = true
hit.Parent:FindFirstChild("Humanoid"):TakeDamage(5)
local vfx = game.ReplicatedStorage.PunchFX.Attachment:Clone()
vfx.Parent = hit.Parent.HumanoidRootPart
local sound = script.Punch:Clone()
sound.Parent = hit.Parent.HumanoidRootPart
sound:Play()
game.Debris:AddItem(sound,2)
local BV = Instance.new("BodyVelocity")
BV.MaxForce, BV.Velocity = Vector3.new(5e4, 5e2, 5e4), plr.Character.HumanoidRootPart.CFrame.lookVector * 20
BV.Parent = hit.Parent.HumanoidRootPart
game.Debris:AddItem(BV, 0.16)
local bool = Instance.new("BoolValue")
bool.Name = "Stunned"
bool.Parent = hit.Parent
game.Debris:AddItem(bool,1)
local hitanim = hit.Parent.Humanoid:LoadAnimation(script.Hit)
hitanim:Play()
game.Debris:AddItem(hitanim,1)
spawn(function()
for i,v in vfx:GetChildren() do
if v:IsA("ParticleEmitter") then
v:Emit(v:GetAttribute("EmitCount"))
end
end
end)
game.Debris:AddItem(vfx,1.5)
task.wait(1)
hitboxcooldown = false
end
end)
elseif Argument == "Last" then
spawn(function()
plr.Character.Humanoid.WalkSpeed = 7
task.wait(.65)
plr.Character.Humanoid.WalkSpeed = 16
end)
task.wait(.25)
local hitbox = Instance.new("Part")
hitbox.Parent = workspace
hitbox.Shape = "Ball"
hitbox.CanCollide = false
hitbox.Anchored = true
hitbox.Size = Vector3.new(11,11,11)
hitbox.BrickColor = BrickColor.new("Really red")
hitbox.Transparency = 1 -- make it .5 for testing
hitbox.CFrame = plr.Character.HumanoidRootPart.CFrame * CFrame.new(0,0, -5)
game.Debris:AddItem(hitbox,1)
local BV2 = Instance.new("BodyVelocity")
BV2.MaxForce, BV2.Velocity = Vector3.new(5e4, 5e2, 5e4), plr.Character.HumanoidRootPart.CFrame.lookVector * 20
BV2.Parent = plr.Character.HumanoidRootPart
game.Debris:AddItem(BV2, 0.16)
local hitboxcooldown = false
hitbox.Touched:Connect(function(hit)
if hit.Parent.Name ~= plr.Name and hit.Parent:FindFirstChild("Humanoid") then
if hitboxcooldown == true then return end
hitboxcooldown = true
hit.Parent:FindFirstChild("Humanoid"):TakeDamage(5)
local vfx = game.ReplicatedStorage.PunchFX.Attachment:Clone()
vfx.Parent = hit.Parent.HumanoidRootPart
local sound = script.Punch:Clone()
sound.Parent = hit.Parent.HumanoidRootPart
sound:Play()
game.Debris:AddItem(sound,2)
local BV = Instance.new("BodyVelocity")
BV.MaxForce, BV.Velocity = Vector3.new(5e4, 5e2, 5e4), plr.Character.HumanoidRootPart.CFrame.lookVector * 80
BV.Parent = hit.Parent.HumanoidRootPart
game.Debris:AddItem(BV, 0.16)
local bool = Instance.new("BoolValue")
bool.Name = "Stunned"
bool.Parent = hit.Parent
game.Debris:AddItem(bool,1)
local Lhitanim = hit.Parent.Humanoid:LoadAnimation(script.LastHit)
Lhitanim:Play()
game.Debris:AddItem(Lhitanim,1)
spawn(function()
for i,v in vfx:GetChildren() do
if v:IsA("ParticleEmitter") then
v:Emit(v:GetAttribute("EmitCount"))
end
end
end)
game.Debris:AddItem(vfx,1.5)
task.wait(1)
hitboxcooldown = false
end
end)
![Screenshot 2024-12-19 214834|321x141](upload://5fq9cH62DzpIbHfTMTFQGGEuSk7.png)
![Screenshot 2024-12-19 214839|243x83](upload://g15ixKbD1utEFvWCwhZgyakjHPy.png)
end
end)
this is the server side