For some reason when I try to die, it won’t fire the event until line 51 but at that point, it will give me just the print(character added). If someone knows why plz tell me.
local ServerStorage = game:GetService("ServerStorage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Map = ReplicatedStorage:WaitForChild("Map")
local Status = ReplicatedStorage:WaitForChild("Status")
local Died
game.Players.PlayerAdded:Connect(function(player)
Died = Instance.new("BoolValue")
Died.Value = false
Died.Parent = player
if #game.Players:GetPlayers() >= 1 then Intermission() else Status.Value = "Wait for 2 or more players" end
player.CharacterAdded:Connect(function(character)
print("character added")
character.Humanoid.Died:Connect(function()
for _,Plr in pairs(game.Players:GetPlayers()) do
if player.Name == Plr.Name then
Died.Value = true
print(Plr)
end
end
end)
end)
end)
function Intermission()
local t = 15
repeat
t = t - 1
wait()
print(t)
Status.Value = "Intermission in "..t
until t == 1
Status.Value = "Beginning game!!"
wait(3)
Map:Clone().Parent = workspace
wait(1)
for i, Plr in pairs(game.Players:GetPlayers()) do
Plr.Character.HumanoidRootPart.CFrame = CFrame.new(workspace.Map.Position + Vector3.new(0,5,0))
print(Plr)
end
end
local RunService = game:GetService('RunService')
function Died(Humanoid, Callback)
return Humanoid:GetPropertyChangedSignal('Health'):Connect(function()
local Health = Humanoid.Health
if (Health < 1) then Callback(Health) end
end)
end
Put it before the check for enough players (I’ll link just the adjusted section).
game.Players.PlayerAdded:Connect(function(player)
Died = Instance.new("BoolValue")
Died.Value = false
Died.Parent = player
player.CharacterAdded:Connect(function(character)
print("character added")
character.Humanoid.Died:Connect(function()
for _,Plr in pairs(game.Players:GetPlayers()) do
if player.Name == Plr.Name then
Died.Value = true
print(Plr)
end
end
end)
end)
if #game.Players:GetPlayers() >= 1 then Intermission() else Status.Value = "Wait for 2 or more players" end
end)
Intermission() has to complete before the line after it is executed, so it has to complete the count down before CharacterAdded is bound. You can call it in a separate coroutine to allow the CharacterAdded bind line to execute when Intermission yields (via wait)
if #game.Players:GetPlayers() >= 2 then -- also pretty sure you want this to run when there's 2 or more players, not 1 or more players.
spawn(function() -- spawn(function) is a roblox global that offers a shorthand syntax for creating then resuming a coroutine.
Intermission()
end)
else
Status.Value = "Wait for 2 or more players"
end
player.CharacterAdded:Connect(function(character)
print("character added")
end)
check out coroutines for a more in depth explanation on what’s going on behind the scenes.
Hi.
I’ve had issues with Humanoid.Died recently too and I realized that the Died event is quite unstable when replacing the StarterCharacter with a custom rig. It does work on client, but the call may be delayed by up to an entire minute on the server sometimes, making it unreliable.
As such, I’ve opted to making my own death notifier which, even if it adds additional delays, lets the player notify the server itself that this player died. Not the best way, clearly not the most secure, but it does work reliably.
Additionally, you could keep track of the player’s health server-sidedly and whenever it reaches <= 0, assume the player died.
I found a way to reliably reproduce Humanoid.Died not firing on the server.
Server attaches a Humanoid.Died handler
Humanoid Root Part’s network owner is the client. When I used SetNetworkOwner(nil) on the HRP then my Server Died handler was fired
Server sets Humanoid.Health to 0
Client receives Humanoid.Died
It was here that the client was setting the HRP to Anchored. This seems to also be a key contributor to the Server not receiving the Humanoid.Died callback.
My solution was to anchor the HRP on the Server Died handler instead of the client Died handler.