I made an reviving system that works like this:
You’re holding E on a player that needs to be revived for 10 seconds
Issues
- First issue is that the animation for player who is ‘dying’ won’t play after he respawns, it only works the first time
- Second issue is that I want the player to lose revive progress after he’s no longer being revived, but he even loses it when hes being revived
Code
Here’s code I use for reviving
local ServerStorage = game:GetService("ServerStorage")
local RunService = game:GetService("RunService")
local beingRevived = false
game:GetService("ReplicatedStorage").Revive.OnServerEvent:Connect(function(player, revivingPlayer)
if revivingPlayer.Parent then
game.Players:GetPlayerFromCharacter(revivingPlayer.Parent).Health.Revive.Value = game.Players:GetPlayerFromCharacter(revivingPlayer.Parent).Health.Revive.Value + 0.25
end
end)
game.Players.PlayerAdded:Connect(function(player)
local Health = player:WaitForChild("Health")
local State = Health.State
local Revive = Health.Revive
local OnLoop = false
player.CharacterAdded:Wait()
wait(0.5)
local animation = player.Character.Humanoid:LoadAnimation(script.Animation)
player.Character.Humanoid.Running:Connect(function(speed)
if State.Value == "Dying" then
if speed > 0 then
animation:AdjustSpeed(1)
else
animation:AdjustSpeed(0)
end
end
end)
State.Changed:Connect(function(change)
print(change)
if change == "Dying" then
animation:Play()
else
animation:Stop()
end
end)
player.Character.Humanoid.Died:Connect(function()
animation:Stop()
end)
while wait(0.125) do
if Revive.Value > 0 then
Revive.Value = Revive.Value - 0.25
end
if Revive.Value >= 100 then
Health.Health.Value = 25
Health.DyingHealth.Value = 50
Revive.Value = 0
end
if Health.DyingHealth.Value <= 0 then
player.Character.Humanoid.Health = 0
end
if Health.State.Value == "Dying" then
if Health.DyingHealth.Value > 0 then
if Revive.Value <= 0 then
Health.DyingHealth.Value = Health.DyingHealth.Value - 0.05
else
Health.DyingHealth.Value = Health.DyingHealth.Value - 0.02
end
end
end
end
end)
There’s also local script that runs RemoteEvent when you hold E on a player