Hiya! I am a beginner scripter, and I am trying to make a cafe register, but I am struggling with Gui. I want to reference a SurfaceGui on the client side using PlayerGui, but my SurfaceGui is not a child of StarterGui. How would I do this without moving the Guis to StarterGui?
Where is the screen Gui located? If it is inside the player, you want to do
game.Players.LocalPlayer.PlayerGui
on the client side
This is where all of the Gui of a player is located
It is in a part inside the workspace if that is what you mean
And you want it to display on the player screen?
It might be easier to just parent it directly to StarterGui, and make it visible when you need to, but if you want to display a ScreenGui in the workspace to a player, you want to clone the ScreenGui and parent it under the player’s PlayerGui
It is a SurfaceGui, not a ScreenGui so not sure how that works. It is parented to a part, and I want it to change for all clients at the same time so I need to use playergui.
Ahh sorry I thought it was ScreenGui
SurfaceGui is object in workspace, which means that it will change for all clients if you change it from a server script
Alright, how do I change it in a server script? Just changing it for the server doesn’t work, so how would I do it? I have seen people use loops like “for _,” but I don’t understand how they work in this context.
Changes on the server automatically replicate to all clients
I don’t think they do, that is the first thing I tried and it only works when you reset character.
you could make a server script that replicates it from ReplicatedStorage into all the clients, setting the adornee to register, this would help( maybe, unless i misunderstood )
Can you share the script you’re using?
Try this;
local POINTER_TO_THE_SURFACE_UI = nil for _,v in pairs(game:GetService("Workspace"):GetDescendants()) do if(v.Name == "SurfaceGui") then POINTER_TO_THE_SURFACE_UI = v break end end
local frame = POINTER_TO_THE_SURFACE_UI.Frame --Assuming you have a frame to change the background of to test that it replicates for all clients
task.wait(20) --Time to boot up the local server with 2 clients ( Dunno if it takes me extra long due to linux :/ )
frame.BackgroundColor3 = Color3.new(1,0,0)
I am confused, “local Screen = nil” changed the variable to nil so it no longer references the screen, and putting “script.Parent.Screen” doesn’t work because that isn’t a variable name.
My bad on using name instead of classname. The nil is because I want to declare a variable, but I havent gotten the value I want to give it yet, which is what the for loop is for.
Also I recommend having the script in ServerScriptService and not in workspace (The cafe register and the surfacegui still needs to be somewhere in the workspace, either directly or indirectly).
task.wait(3) -- To let workspace load everything in
local POINTER_TO_THE_SURFACE_UI = nil for _,v in pairs(game:GetService("Workspace"):GetDescendants()) do if(v.ClassName == "SurfaceGui") then POINTER_TO_THE_SURFACE_UI = v break end end -- Finds the first SurfaceGui in workspace regardless of it's name (my bad on the first one)
if not(POINTER_TO_THE_SURFACE_UI) then warn("Couldn't find a surfacegui!!!") end -- Checks that a surfacegui was found
local frame = nil for _,v in pairs(POINTER_TO_THE_SURFACE_UI:GetDescendants()) do if(v.ClassName == "Frame") then frame = v break end end -- Finds the first Frame in the surfacegui, also regardless of name
if not(frame) then warn("Couldn't find a frame anywhere in the surfacegui called \""..POINTER_TO_THE_SURFACE_UI.Name.."\"") end -- Check that a frame was found in the surfacegui
task.wait(20) --Time to boot up the local server with 2 clients ( Dunno if it takes me extra long due to linux :/ )
frame.BackgroundColor3 = Color3.new(1,0,0) -- Sets the backgroundcolor of the frame to see that it has changed successfully
If you put this in a script in ServerScriptService and make sure the cafe register is anywhere in the workspace, then that the surfacegui is in the cafe register and has a frame in it.
This should work if you test a local server (also in a game with 2 players). Afterwards for efficiency and readability, it’d be a good idea to remove the for loops and point the variables directly to the objects like local gui = workspace["The Ultimate Cafe"]["cafe register4000"]["cool cafe register screen"]
etc
Simple way is just to use tags via CollectionService.
You can assign a tag to the SurfaceGui which you can then get with CollectionService later, or just reference the SurfaceGui directly.
-- Local Script Example
local surfaceGui = workspace.Cafe.Part.SurfaceGui