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

Trying to make a Server System Message? [ANSWERED]

So I am trying to make a Server System Message, but right now, it only sends to the client, could you please review my code and say what's wrong with it, and what I need to change? LocalScript in StarterPlayerScripts:

	Player = game.Players.LocalPlayer
	 
	Character = Player.CharacterAdded:Wait()
	 
	Humanoid = Character:WaitForChild("Humanoid")
	 
	Humanoid.Died:Connect(function()
	game.ReplicatedStorage.YourEvent:FireServer()
	end)
	 
	game.ReplicatedStorage.YourEvent2.OnClientEvent:Connect(function(DiedPlayer)--[[Your Event is a placeholder, just incase it wasnt clear.]]
	   game.StarterGui:SetCore("ChatMakeSystemMessage", {
	        Text = DiedPlayer.." has died!",
	        Color = Color3.fromRGB(255,0,0),
	        Font = Enum.Font.SourceSansBold
	    })
	end)

Server Script in SSS(ServerScriptService):

game.ReplicatedStorage.YourEvent.OnServerEvent:Connect(function(plr)
	local DiedPlayer = plr.Name
	game.ReplicatedStorage.YourEvent2:FireAllClients(DiedPlayer)--Same Here.
	end)

The problem is, it does work for every player, but only works once. It says that a player has died when they died only once, and when they die again, the message doesn't popup. Any help? Thanks! :D I eventually got help, now it's working fine! Thanks to all who tried!

2 answers

First, create a localscript with the following code in starterplayerscripts:

Player = game.Players.LocalPlayer 

Character = Player.CharacterAdded:wait()

Humanoid = Character:WaitForChild("Humanoid")

Humanoid.Died:Connect(function()
game.ReplicatedStorage.YourEvent:FireServer()
end)

game.ReplicatedStorage.YourEvent2.OnClientEvent:Connect(function(DiedPlayer)--[[Your Event is a placeholder, just incase it wasnt clear.]]
   game.StarterGui:SetCore("ChatMakeSystemMessage", {
        Text =DiedPlayer.." has died!",
        Color = Color3.fromRGB(255,0,0),
        Font = Enum.Font.SourceSansBold
    })
end)

In the ServerScript:

game.ReplicatedStorage.YourEvent.OnServerEvent:Connect(function(plr)
local DiedPlayer = plr.Name 
game.ReplicatedStorage.YourEvent2:FireAllClients(DiedPlayer)--Same Here.
end)

Havent tested it yet, so it might be full with errors, ill update it once i checked it.

The thing is that if you want to keep your code put it into StarterGui as codes run again every single time you respawn, in StarterPlayerScripts it runs once so if you want it there you will have to use player.CharacterAppearanceLoaded() function (Or character added but the first one is better) and then do the stuff with humanoid, the reason why it does nothing is because you define humanoid of the first character that spawns but then the character destroys so humanoid becomes nil, the variable stays so you are trying to do stuff with nil for the second time.

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