(This is an example) So I was thinking of making a “serverscript” in which I write a number there, using a remote event (Server-> Client) and in a “client script” it will put in a “textlabel” the number that the “serverscript” had put.
The problem is that I never used remote events in Guis and I am confused by how to do this, can someone give an example of how to do this?
If you would like to have a GUI that is “server sided”, you could use a loop to add it to every player’s PlayerGui. For example:
for i,v in pairs(game.Players:GetPlayers()) do
Instance.new("ScreenGui",v.PlayerGui)
end
This would loop through all players and create a ScreenGui, parented to their PlayerGui.
i know how to do it, but i would like to know how to do it by remote events (but thanks for that answer).
You will have a RemoteEvent instance kept inside of ReplicatedStorage
since this is a part of Roblox’s Server Client Model that both the server and client can access.
Server Sided Scripts:
On the server you will have presumably a function that requires a player
and value
to be declared. If you know how to use ModuleScripts this would be a great function to use in ModuleScript so you can use it across all your server scripts.
local function updateNumber(player, value)
remoteEvent:FireClient(player, value)
end
updateNumber(xZylter,100)
Local Sided Scripts:
Now since each player will have their own local script the server handles who needs the information and on the client side you just need to listen for the event.
local function updateNumberOnGUI(value)
gui.TextLabel.Text = value
end
remoteEvent.OnClientEvent:Connect(updateNumberOnGUI)
Feel free to ask more questions.
remoteEvent.FireClient(remoteEvent, player, value)
remoteEvent:FireClient(player, value)
I noticed that there was an error, but what does “xZylter” mean?
You want to pass the player object, which is inside the Players service.
updateNumber(game:GetService(“Players”).xZylter, 100)
It was part of my example to call the function. The first parameter in the function is the player you want to send the information to.
Thanks for finding that, I always forget that.
I haven’t figured out what “xZylter” does yet, but I’ll see if I understand.
I suggest reading the RemoteEvent API Reference if you want a indepth explenation on RemoteEvents. When doing RemoteEvent:FireClient()
the first parameter is always the player you are sending the information to. In my example I simplified it to just have my username.
OK thank you i will take a few hours to look at this to understand once and for all.
Technically speaking you can alter the playergui on the server side. Developers typically don’t do this which is understandable since there would definitely be lag on the change since obviously the server is handling this and server run time always will be ahead of the client. But I’ve used it on multiple occasions if everybody was to see this UI of yours it might be worth considering. But in actuality it’s very simple. You just :FireClient(playerObject) or if it’s to all players :FireAllClients()
xZylter is just the person who gave you the answer. His example is just showing you put in a player name.
“Technically speaking you can alter the playergui on the server side. Developers typically don’t do this which is understandable since there would definitely be lag on the change since obviously the server is handling this and server run time always will be ahead of the client”. I know how to do it, but I don’t like to do it for the reason you mentioned.
thanks for helping, this i already understood but i will now see the dev wiki to learn more.
Ok to sum it up, I already realized but I did the script differently to stay as I want, but thanks for all the help.