Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Help needed on death announcement?

I am writing a script to make text appear at the top of the screen whenever somebody dies. (the text will stay there forever until someone else dies) There is this one thing that i think will need to be included in the code that I don't know about yet; how do you find the name of a player who has died?

1 answer

✓ Accepted answer

Assuming you are recording player deaths server-side, we can use use the Humanoid.Died event to detect player death. But, how do we find and get the player? We can use the PlayerAdded event to detect when a player joins and get their name. Example:

--This is a server script!
game:GetService("Players").PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		Character.Humanoid.Died:Connect(function()
			--do thing
			print(Player.Name) --Prints the name of the player who died
		end)
	end)
end)

So now we need to make a text appear on top of everyone's screen. We can use RemoteEvents and use it's :FireAllClients event to create a TextLabel for everyone to see

--The server script
game:GetService("ReplicatedStorage").PlayerDeath:FireAllClients(Player)

and on a local script, possibly in a ScreenGui?

--This is a client script!
game:GetService("ReplicatedStorage").PlayerDeath.OnClientEvent:Connect(function(Player)
	TextLabel.Text = Player.Name.." has died!"
end)

Now you know you can use RemoteEvents and Server-side events to record player deaths! Please mark as the solution if this worked for you!

This discussion is preserved as it was. New answers, comments, and votes are closed.