I tried putting a script into ServerScriptService to determine when a player dies, but it dowsnt work! ~~~~~~~~~~~~~~~~~
local plrs = game:GetService("Players")
local plr = plrs.LocalPlayer
local char = plr.Character or plr.Character:Wait()
char.Humanoid.Died:Connect(function() game:GetService("Chat"):Chat(workspace.Radio, plr.Name "Has Died", Enum.ChatColor.Red) end) ~~~~~~~~~~~~~~~~~
You can't use LocalPlayer
inside a Server Script, most of people do that. It's only used on LocalScript
. To get the player, use the playerAdded event.
game.Players.PlayerAdded:Connect(function(player) -- code here end)
Also, to get the character, use the characterAdded event.
game.Players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(char) -- code here end) end)
Your error is on the line:
local char = plr.Character or plr.Character:Wait()
It should be:
local char = plr.Character or plr.CharacterAdded:Wait()
Try this:
local plrs = game.Players:GetChildren() for i = 1,#plrs do plrs[i].Humanoid.Died:Connect(function() local char = plr.Character game:GetService("Chat"):Chat(workspace.Radio, plr.Name "Has Died", Enum.ChatColor.Red) end) end
Give me a message if this doesn't work