Need help with PlayerGui

Hi there!

I am trying to make a game announcement using a Screen Gui that announces what the next selected game mode will be. I am now faced with a problem where I managed to get the ScreenGUI that I cloned from ServerReplicatedStorage to be parented to the PlayerGui in Players, but unable to actually see any of the Gui’s contents.

I am unsure if this method even works. Currently this is the how I envisioned the whole process to be.

  1. Player touches a part that will run the script shown below
  2. Script will place the Cloned “ServerGui” in ServerReplicatedStorage to the PlayerGui in Players
  3. GameMode will be selected and instructions using GuiText will be sent to “ServerGUI”

image

local MF = script.Parent
local SGUI = game:GetService("ReplicatedStorage")["Local Player GUI"].ServerGUI
local ANTISPAM = {}

MF.Touched:Connect(function(hit)
	
	local playeruser = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
	if table.find(ANTISPAM, playeruser) then 
		end
	if not table.find(ANTISPAM, playeruser) then	
		table.insert(ANTISPAM, playeruser)
		local CSGUI = SGUI:Clone()
		CSGUI.Parent = playeruser.PlayerGui
	end
end)

1 Like

The most efficient way to do this would most likely be to keep the GUI in StarterGui, but set all the transparency properties to invisible. Then, add a LocalScript that will control the text and transparency of the GUI. You can use a RemoteEvent to communicate between the client and the server. This means you could also animate it using the TweenService if you wanted to.

1 Like

your method should work, the script and everything else seems fine, it might be that the ui isnt visible or has nothing to display

1 Like

no put the GUI into the StarterGui and make the screenGUI enabled too false.

and if you want to see the UI then turn enabled to true

1 Like

My understanding might be flawed but do correct me if I am wrong.

I have main script that controls the gamemode. Once the Gamemode is randomly selected, it is suppose to send a server wide instruction to every player. I would then update the playerGui using the main script?

I checked and everything is enabled.

if you are right then im not sure why it doesnt show but i usually do this and everything works fine
check if the label has any text input in it or if its transparent or not, otherwise you should try remoteevents like the other person suggested

what they meant is to have a remoteevent, in the server script do remote:FireAllClients(selectedgamemode) and connect a listener in the client script

remote.OnClientEvent:Connect(function() 
-- do stuff 
end)```
1 Like

make a remote event.

if the server wants to do something with the GUI’s, use the :FireClient() or :FireAllClients() events.

and on the client do whatever you want to do with the GUI or something

Note: always use local scripts when dealing with GUI’s

edit: added more words.

The local script is where I mess with the GUI? If so where should I placed the local script?

Am I correct in thinking you only want to update the gamemode text of the TextLabel?

If so, you could use a RemoteEvent and fire the text you want down it to all the clients using the FireAllClients() function. Then, in a LocalScript as a child of the TextLabel, ising that to set the text.

say the local script and i will tell you where to put it

Place the LocalScript as a child of the TextLabel. Then, the code would be something like:

event.OnClientEvent:Connect(function(text)
    script.Parent.Text = text
end)

Then, on the server side, you could do the following:

-- where the text variable contains the gamemode

event:FireAllClients(text)

This is all based on placing the ServerGui and its contents into the StarterGui?

I have yet to make one. I am not that familiar with local scripts and remote events

i have a better version of your script

event.OnClientEvent:Connect(function(text)
    script.Parent.Visible = true -- This is to make sure that the textlabel is visible and good to go
    script.Parent.Text = text
    -- The code below is optional if you wanted, it basically sets the textlabel visible to false after a few seconds
    wait(3)
    script.Parent.Visible = false
end)
1 Like

Basically, instead of managing all PlayerGui server side, the server will pass the information to the client, and the client will manage the text for only that client. The FireAllClients() function will tell all clients to update the text, therefore making it more efficient and easier to achieve what you are trying to do.

1 Like

Since a LocalScript will run on the client’s device, it will only update for them.

1 Like

Alright. This is how the process should work.

Place ServerGui and Announcemnt Text Label into ScreenGui. (A local script will be placed into Text Label, which contains different functions with predetermined texts that will only connect when the Main Script fires all Clients?)

Do I still retain the .Touched part that is responsible in firing the remote event or do I only allow the remote event to be fired after the selected game mode?