Gui:SetCore("chat make system message", { only fires for one player

I’m working on a specific message that appears in the chat for everyone when a certain player touches the checkpoint. The message that gets fired from the script, only appears for the player who touched the checkpoint, but I want it to show up for every player on the server.

The script is a local script inside of starterGui:

local plr = game.Players.LocalPlayer
local Stage15 = game.Workspace.Checkpoints["15"]
local debounce15 = true
Stage15.Touched:Connect(function(part)
	local stage = plr:WaitForChild("leaderstats")
	if plr.Character and part:IsDescendantOf(plr.Character) and stage.Stage.Value == 30 then
		if debounce15 == true then
			debounce15 = false
			game.StarterGui:SetCore("ChatMakeSystemMessage",{
				Text = game.Players.LocalPlayer.Name.." has reached the Automatic Difficulty!";
				Color = Color3.new(0, 0.666667, 0);
				Font = Enum.Font.SourceSansBold;
				FontSize = Enum.FontSize.Size32
			})
			wait(9999)
			debounce15 = true
		end
	end
end)

If anyone can help, I’d appreciate it!

Change to a server script.

And instead of LocalPlayer, just get the hit parent name.

1 Like

I tried this but it didn’t work:

local Stage15 = game.Workspace.Checkpoints["15"]
local debounce15 = true
Stage15.Touched:Connect(function(hit,player,plr)
	local stage = plr:WaitForChild("leaderstats")
	if hit.Parent:FindFirstChild("Humanoid")and stage.Stage.Value == 30 then
		if debounce15 == true then
			debounce15 = false
			game.StarterGui:SetCore("ChatMakeSystemMessage",{
				Text = game.Players.LocalPlayer.Name.." has reached the Automatic Difficulty!";
				Color = Color3.new(0, 0.666667, 0);
				Font = Enum.Font.SourceSansBold;
				FontSize = Enum.FontSize.Size32
			})
			wait(9999)
			debounce15 = true
		end
	end
end)

@lrisDev

My apologies, what you would do is upon a player touching the stage part, fire a remote event to all clients since you cannot call SetCore from a server script. On the LocalScript listen for when the event is fired and then use SetCore so all the people in the game will get the message

Do you know how I can type that? I just don’t really understand remote events.

No problem at all!

A remote event is used to communicate between the server and the client.

So what most people do is put their remote events within ReplicatedStorage (since they are shared both between the server and the client)

In the server script I believe the code should look like this:

note: within the touched event, always remember that the TouchedEvent only has one parameter which is the object that hit the part.

Also, you are able to pass data through the remote event by putting the data within the parenthesis

local StageCompleted = put the path to the remote event here and name the variable to whatever you like!
local Stage15 = game.Workspace.Checkpoints["15"]
local debounce15 = true
Stage15.Touched:Connect(function(hit,player,plr)
	local stage = plr:WaitForChild("leaderstats")
	if hit.Parent:FindFirstChild("Humanoid") and stage.Stage.Value == 30 then
		if debounce15 == true then
			debounce15 = false
                 local name = game.Players:GetPlayerFromCharacter(hit.Parent).Name
		         StageCompleted:FireAllClients(name)
			wait(9999)
			debounce15 = true
		end
	end
end)

Now somewhere in a LocalScript (I suggest you put it inside StarterPlayerScripts) go ahead and put this code, this is where we will make the event connection:

local StageCompleted = put the path to the remote event here and name the variable to whatever you like!

function onEvent(playerName)
     game.StarterGui:SetCore("ChatMakeSystemMessage",{
		Text = playerName.."Someone has joined the game";
		Color = Color3.new(0, 0.666667, 0);
		Font = Enum.Font.SourceSansBold;
		FontSize = Enum.FontSize.Size32
	})
end
StageCompleted.OnClientEvent:Connect(onEvent)

Edit: Please do let me know of any syntax error, chances are I made a typo or something

Yet another edit: If you want to find out more about remote events, check out this video by @Alvin_Blox

1 Like

I got an error in the first script- Players.Player1.PlayerGui.DifficultyReachedTest:5: attempt to index nil with ‘WaitForChild’

That’s because on the touched event in the server script only the hit value is defined also that code would be unreliable since if someone was wearing an accessory that covers their legs it would break your code.

Here should be your fixed server code:

local StageCompleted = put the path to the remote event here
local Stage15 = game.Workspace.Checkpoints["15"]
local debounce15 = true
Stage15.Touched:Connect(function(hit)
	local plr = game.Players:GetPlayerFromCharacter(hit:FindFirstAncestorOfClass("Model"))
	local stage = plr:WaitForChild("leaderstats")
	if hit:FindFirstAncestorOfClass("Model"):FindFirstChild("Humanoid") and stage.Stage.Value == 30 then
		if debounce15 == true then
			debounce15 = false
                 local name = plr.Name
		         StageCompleted:FireAllClients(name)
			wait(9999)
			debounce15 = true
		end
	end
end)

The reason for this is because you added two extra arguments to the Touched event. In order to fix, you will need to remove the “plr” and “player” in the touched event and then store the player in a variable using

local player = game.Players:GetPlayerFromCharacter(hit.Parent)

That method will return the Player, it is then you will be able to reference leaderstats, sorry for the long wait.

1 Like

Yes this will work, however rather than using hit.Parent I’d recommend using

hit:FindFirstAncestorOfClass("Model")

Because if you use hit.Parent there is a chance that an accessory might hit it.

You did recover from this flaw by typing:

ìf hit.Parent:FindFirstChild("Humanoid") ...

However to guarantee that it will work every time use:

hit:FindFirstAncestorOfClass("Model")
2 Likes

I managed to fix it. Thank you for helping!

1 Like