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
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
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.
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)
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.
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)