Hello devs, I am making a script that puts a “Respawning in 5” above the player’s head when dead.
Here is the script:
local respawnTime = game.Players.RespawnTime
local tag = script.Parent.Dead
game.Players.PlayerAdded:Connect(function(p)
p.CharacterAdded:Connect(function(ch)
ch.Humanoid.Died:Connect(function()
local nowTag = tag:Clone()
local respawnTime2 = respawnTime
nowTag.Parent = ch.Head
while wait() do
if respawnTime2 <= 0 then
nowTag.LowerText.Text = 0
break
else
wait(0.1)
respawnTime2 = respawnTime2 - 0.1
nowTag.LowerText.Text = respawnTime2
end
end
end)
end)
end)
It goes too slow though but it seems right to me.
Here is the video:
The video wasn’t edited or cut and the respawn time is 5 seconds.
I assumed that since you were subtracting 0.1 from the timer in your original code I thought you wanted to include tenths of seconds. Here I changed it so that it only counts seconds and adds the “.0” at the end for aesthetics.
attempt to perform arithmetic (add) on nil and number
local respawnTime = game.Players.RespawnTime
local runService = game:GetService("RunService")
local tag = script.Parent.Dead
game.Players.PlayerAdded:Connect(function(p)
p.CharacterAdded:Connect(function(ch)
ch.Humanoid.Died:Connect(function()
local nowTag = tag:Clone()
local respawnTime2 = respawnTime
nowTag.Parent = ch.Head
local respawn = tick() + respawnTime
local timer
while (tick() < respawn) do
timer = math.floor(timer + 0.5)
nowTag.LowerText.Text = timer..".0"
runService.Heartbeat:Wait()
end
nowTag.LowerText.Text = "0.0"
end)
end)
end)
Errors at line 15 which is timer = math.floor(timer + 0.5)