I want to make a gui not local, someone told me it’s possible but idk how
What do you mean? When you put a UI inside StarterGui, everyone in the game would see that gui , however - if they commit actions only on their client, those changes would only be seen to that client.
how to commit action that everyone will see
InvokeServer() – remote function
FireServer() - remote event
so when i want to do the action, fire the server, and make a local script and do the action?
Here is a very classic/simple example :
Client
--Put this inside a local script under a textButton
local ReplicatedStorage= game:GetService("ReplicatedStorage")
local event = ReplicatedStorage:WaitForChild("Baseplate")
script.Parent.MouseButton1Click:Connect(function()
event:FireServer()
end)
Server
game.ReplicatedStorage.Baseplate.OnServerEvent:Connect(function(Player)
game.Workspace.Baseplate.BrickColor = BrickColor.random()
end)
This will result in -
Once any player clicks on this button, the color of the baseplate part would be changed into a random color - and will be shown to everyone in the game.
Important
When using ‘fireServer’ or ‘InvokeServer’, the first argument on the server will always be the player.
On the client you won’t have to put the player who pressed, it’s automatically there.
Bases on this example,
you could make it so whenever a client presses on that button, it’d create a frame on every client in your game.
Server
game.ReplicatedStorage.UI.OnServerEvent:Connect(function(Player)
local clone = game.ReplicatedStorage:WaitForChild("Example")
for a,b in pairs(game.Players:GetPlayers()) do
if not b.PlayerGui:WaitForChild("Test"):FindFirstChild(clone.Name) then
clone:clone().Parent = b.PlayerGui.Test
end
end
end)
Client
local ReplicatedStorage= game:GetService("ReplicatedStorage")
local event = ReplicatedStorage:WaitForChild("UI")
script.Parent.MouseButton1Click:Connect(function()
event:FireServer()
end)
Mark it as a solution if you succeeded with it and it helpd you.
:FireServer() since you’re on the client, there’s a few examples of how you would do it above.
Surely you would use FireAllClients on server?
Yes, “FireAllClients” is from the server, but I usually don’t use it. Only if needed
Well yeah, that goes for nearly everything, I usually don’t make UI’s, but if it is needed I will use it. FireAllClients is pretty clean anyways, it’s a good alternative to looping through all players, if that was what you were thinking…