Another way to send message to whole server from a script

I can’t send my message to the server. It keeps saying to use local scripts to do this, but when I tried doing so the message was only visible to their screen (the client). What am I supposed to do?

The Script:

1. local StarterGui = game:GetService("StarterGui")
2. local Button = script.Parent
3. spawn(function()
4. 	
5. 	while wait() do
6. 		
7. 		local Gui = script.Parent.Parent
8. 		local R = tonumber(Gui.R.Text)
9. 		local G = tonumber(Gui.G.Text)
10. 		local B = tonumber(Gui.B.Text)
11. 		
12. 		local SavedColor = Gui.Color
13. 		
14. 		SavedColor.Value = Color3.fromRGB(R,G,B)
15. 		Gui.ColorPicker.BackgroundColor3 = Color3.fromRGB(R,G,B)
16. 		
17. 	end
18. 	
19. end)

20. Button.MouseButton1Click:Connect(function()
21. 	
22. 	local Gui = script.Parent.Parent
23. 	
24. 	local Message = Gui.Message
25. 	local R = Gui.R
26. 	local G = Gui.G
27. 	local B = Gui.B
28. 	local Font = Gui.Font
29. 	
30. 	script.Parent.Parent.SendMessage:FireServer(Message.Text, R, G, B, Font.Text)
31. 	
32. end)

You indeed have to use localscripts for this, to make it visible for all players you can use an in pairs loop.

for _, player in pairs(game.Players:GetPlayers()) do
     
     local playerGui = player:FindFirstChild("PlayerGui")

     if playerGui then
          -- Message code in here
     end

end
1 Like

It still didn’t work. I got another error saying: SetCore is not a valid member of PlayerGui “Players.Seeker4050.PlayerGui”

I remade this code here:

1. for _, Player in pairs(game.Players:GetPlayers()) do

2. 		local PlayerGui = Player:FindFirstChild("PlayerGui")

3. 		if PlayerGui then
4. 			
5. 			PlayerGui:SetCore("ChatMakeSystemMessage", {
6. 				
7. 				Text = Message.Text,
8. 				Color = Gui.Color.Value,
9. 				Font = Enum.Font[Font.Text],
10. 				Size = Enum.FontSize.Size10
11. 				
12. 			})
13. 			
14. 		end

15. 	end

It is a local script, right? That could be the problem.

1 Like

It is in a local script but I get the error still.

Edit: I converted everything from that script into the local script.

I’m not absolutely sure, but those numbers on the side of the script could have something to do with it. It may or it may not, I’m not sure. Normally when you post code the numbers aren’t there.

What side of the script? Can you include a quote with the side your talking about?

Nevermind, I see the bug, I know what you want to do, make a serverscript first and paste this code into it.

First, make a remote event in replicatedstorage and call it MessageEvent.

Now, create the script in serverscriptservice and put this code into it.

local time = 60 -- How many seconds it would take to set a new message

while wait(time) do -- A loop to repeat the message
     game.ReplicatedStorage.MessageEvent:FireAllClients() -- Fire the message event to all clients
end

Now, create the localscript and put this code into it:

game.ReplicatedStorage.MessageEvent.OnClientEvent:Connect(function()
    game:GetService("StarterGui"):SetCore("ChatMakeSystemMessage", {
        Text = Message.Text,
        Color = Gui.Color.Value,
        Font = Enum.Font[Font.Text],
        Size = Enum.FontSize.Size10
    })
end)
1 Like

I actually want the player to be able to send the data. Which is from a UI button to send.

Oh alright, then you’d have to use remotefunctions, but I have to go now.

1 Like

Just with the code you pasted, it has the numbers on it:
1.
2.
3.
etc
That could be a reason, I’m not entirely sure.

1 Like

He wants that the client can decide what’s on the message.

1 Like

Those are examples of the number of the codeline’s space.

1 Like

Oh, ok. Thanks, that clears it up.

1 Like

Alright, I have a bit more time, with bindable functions you can fire something to the server and return it to the client again, you can use this to tell the server that a player has sent the data and then the server returns that to all players, but maybe try that yourself and see how far you come.

AlvinBlox has a great tutorial on it.

1 Like

I’m getting no error and it still doesn’t show on the other client.

Did I read instructions correctly? I will send you screenshots of the Explorer and Script

image

Inside Script (In ServerScriptService):

  1. game.ReplicatedStorage.Event.OnServerEvent:Connect(function()
    2.
    3. game.ReplicatedStorage.MessageEvent:FireAllClients()
    4.
    5. end)

Inside Sender:

1. local StarterGui = game:GetService("StarterGui")
2. local Button = script.Parent

3. spawn(function()
4. 	
5. 	while wait() do
6. 		
7. 		local Gui = script.Parent.Parent
8. 		local R = tonumber(Gui.R.Text)
9. 		local G = tonumber(Gui.G.Text)
10. 		local B = tonumber(Gui.B.Text)
11. 		
12. 		local SavedColor = Gui.Color
13. 		
14. 		SavedColor.Value = Color3.fromRGB(R,G,B)
15. 		Gui.ColorPicker.BackgroundColor3 = Color3.fromRGB(R,G,B)
16. 		
17. 	end
18. 	
19. end)

20. game.ReplicatedStorage.MessageEvent.OnClientEvent:Connect(function()
21. 	
22. 	local Gui = script.Parent.Parent

23. 	local Message = Gui.Message
24. 	local R = Gui.R
25. 	local G = Gui.G
26. 	local B = Gui.B
27. 	local Font = Gui.Font
28. 	
29. 	game:GetService("StarterGui"):SetCore("ChatMakeSystemMessage", {
30. 		Text = Message.Text,
31. 		Color = Gui.Color.Value,
32. 		Font = Enum.Font[Font.Text],
33. 		Size = Enum.FontSize.Size10
34. 	})
35. end)

36. Button.MouseButton1Click:Connect(function()
37. 	
38. 	local Gui = script.Parent.Parent
39. 	
40. 	local Message = Gui.Message
41. 	local R = Gui.R
42. 	local G = Gui.G
43. 	local B = Gui.B
44. 	local Font = Gui.Font
45. 	
46. 	game.ReplicatedStorage.Event:FireServer()
47. 	
48. end)