My server chat doesn't replicate on all clients

I wrote some code for a server chat but it does no replicate for all servers. Its supposed to be a chat that when a player died every one should be able to see it. The problem is that I tested it and only I can see the server death chat when I die. So, everyone can only see their death messages not anyone’s in the server. Here is my code:

--in a local script 
game.Lighting.Blur.Size = 0
local player = game.Players.LocalPlayer
wait(2)
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")

local frame = script.Parent.Frame


local sm
local messages = {
	" kicked the can.",
	" couldn't make it.",
	" is dead.",
	" has vanished.",
	" is not spoken of.",
	" disappeared.",
	" met adversity.",
}

humanoid.Died:Connect(function()
	
	sm = BrickColor.new ("Crimson")
	game.StarterGui:SetCore("ChatMakeSystemMessage", {
		Text = player.Name .. messages[math.random(1, #messages)];
		Font = Enum.Font.ArialBold;
		Color = sm.Color;
		FontSize = Enum.FontSize.Size96;
	})
	
	script.Parent.Between:Play()
	frame.BackgroundTransparency = 0
	frame.Visible = true
	
	for i = 0, 1, 0.01 do
		frame.BackgroundTransparency = i
		wait(0.2)
	end
	frame.Visible = false
	frame.BackgroundTransparency = 1
end)

humanoid.HealthChanged:Connect(function(newHealth)
	game.Lighting.Blur.Size = 56-newHealth
end)

Any replies are thanked!

You should probably use MessagingService for this:

Thanks Jack. I’ll check it out!

I’m sorry I meant to say that its not replicating on all clients. Its like in SCP-3008 when you die it chats that the player died. For me, its not working.

Oooh I see

Alrighty, what you could do instead is use a PlayerAdded event on the server side & detect when a Character will die that way, you could probably something like this:

--Server Script inside ServerScriptService
local sm
local messages = {
	" kicked the can.",
	" couldn't make it.",
	" is dead.",
	" has vanished.",
	" is not spoken of.",
	" disappeared.",
	" met adversity.",
}

game.Players.PlayerAdded:Connect(function(Player)
    Player.CharacterAdded:Connect(function(Character)
        local Humanoid = Character:WaitForChild("Humanoid")
        Humanoid.Died:Connect(function()

        	sm = BrickColor.new ("Crimson")
	        game.StarterGui:SetCore("ChatMakeSystemMessage", {
   		    Text = player.Name .. messages[math.random(1, #messages)];
		    Font = Enum.Font.ArialBold;
		    Color = sm.Color;
		    FontSize = Enum.FontSize.Size96;
	    })
        end)
    end)
end)

This should work so that all players can see the message

1 Like

I will try it. Thanks so much for your time. :grinning_face_with_smiling_eyes:

I got an error saying…:frowning:

StarterGui:SetCore must be called from a local script
1 Like

I think:

Only works on the client. That is why it isn’t working.

Try using a remote event and doing something like:

local message = -- get your random message
WoahSomeoneDiedEvent:FireAllClients(message)

And on the client, do something like:

DeathMessageEvent.OnClientEvent:Connect(function(msg)
   game.StarterGui:SetCore("ChatMakeSystemMessage", {
		Text = player.Name..msg
		Font = Enum.Font.ArialBold;
		Color = sm.Color;
		FontSize = Enum.FontSize.Size96;
	})
end)

mine was originally in a local script

Yes, but PlayerAdded does not work in local scripts. As stated, use remote events. I edited my post to have a rough example of how it should be done.

Maybe I should use the FireAllClients() function…

I swear that used to work on the server before

Ok just use a RemoteEvent then to fire that message from the server to the client so that all clients can see it

I will do it @synical4. I think this will work

1 Like

Yup. Looping through players and doing everyone would be terrible :sweat_smile: