I’m currently trying to make a box on the bottom of the screen that displays to all players some text. I’m also trying to clone something from the ReplicatedStorage so everyone can see it. However, I’m not sure of whether to use a ServerScript or LocalScript as it has to doesn’t have much to do with individual players but I don’t want to add too much load to the server.
Would it be smartest to go local or stay server sided?
Asuming you’re using the server to transmit some sort of message, you can use RemoteEvents with their :FireAllClients() method to transmit information to a LocalScript, where the text can be displayed and manipulated accordingly. If you’re unfamiliar with Remotes and how to use them, I recommend this article on the developer hub.
How would I fire all the LocalScripts of all the players? Let’s say I have a part that a player can click; how would I communicate with all the players in the server?
RemoteEvents come with 2 “server to client” broadcasting methods you can use to transmit data.
:FireClient(player, …) - This method requires a specified player as it’s first argument, and if used the server will only broadcast to that one player. This method is really useful, although it’s not the one you want to use.
:FireAllClients(…) - This is probably the method you’re looking for. This method doesn’t have any required arguments, since it will simply broadcast to all players currently present in the game.
Ah, that’s not quite it! You’ll need a normal, server sided script to listen for clicks on the block. When a click is detected, that script will then utilize the :FireAllClients() method, which will provide the (LocalScripts) players with information.
To be a bit more clear, here’s a code sample. It will show a message on everyones screen when a specific part is touched.
(Server) A script inside of a part with a ClickDetector:
local Part = script.Parent
local ClickDetector = Part.ClickDetector
local Event = game:GetService("ReplicatedStorage").SendMessage
ClickDetector.MouseClick:Connect(function()
Event:FireAllClients("A player just clicked the part")
end)
(Client) A localscript inside of a TextLabel.
local Label = script.Parent
local Event = game:GetService("ReplicatedStorage").SendMessage
Event.OnClientEvent:Connect(function(Message)
Label.Text = Message
wait(5)
Label.Text = ""
end)
The client-server model is quite hard to get the hang of, but when you’ve learned it you’ll find it much easier. You got it!