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

How to make a server chat message when player dies?

The result I am looking for is like what happens in the game "Lab experiment". The server automatically chats (player name) (random message), what I thought is that it sends the player name in an event, then from there it runs a math.random for the message, so I tried this:

game.Players.PlayerAdded:connect(function(player)

	local name = player.Name
	game.ReplicatedStorage.LocalPlayer.Value = name
	player.CharacterAdded:Connect(function(character)
			character:WaitForChild("Humanoid").Died:Connect(function()
				game.ReplicatedStorage.RemoteEvents.deathMessage:FireClient(player,name)
			end)

then from a local script:

function msg(plr,name)
	local i = math.random(1,5)
	if i == 1 then
	local selected = "has forgotten how to breathe"
	elseif i == 2 then
	local selected = "just oofed"
	elseif i == 3 then
	local selected = "used an old meme"
	elseif i == 4 then
	local selected = "commited big oof"
	elseif i == 5 then
	local selected = "has fallen and cannot get up!"
	
	game.StarterGui:SetCore("ChatMakeSystemMessage", {
		Text = name.." "..selected;
	})
	end
end
game.ReplicatedStorage.RemoteEvents.deathMessage.OnClientEvent:Connect(msg)

it does not work, and I feel like if it did, it would give different messages to other players when a player dies.

1 answer

✓ Accepted answer

Use the FireAllClients method instead of FireClient method.

game.ReplicatedStorage.RemoteEvents.deathMessage:FireAllClients(msg)

1 comment

0

This was sort of a half answer, but I figured it out with your help. Thanks!

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