Why is my Gui not showing on the client side

Hi, I have a script that should enable a screenGui in the playerGui when some conditions are met. However sometimes it works and sometimes it doesn’t. A few things to note are:

  1. The players die shortly before the gui is enabled (resetOnspawn is false)
  2. When I go on the server it says its enabled for that players playerGui but then when I look on the clients playerGui it says its not.
  3. Sometimes it works perfectly which is weird

If you have any ideas please let me know, I can share the code but its very long and hard to explain, but if you need it let me know.

2 Likes

Have you tried to fire an event to the client whenever you want the gui to show/hide?

3 Likes

No, I just do it in the server like this

losers[i].PlayerGui.DonationPage.Frame.NameFrame.Player1Frame.Visible = true
1 Like

Unfortunately, you can only change the GUI on the client side.
Try RemoteEvents

2 Likes

Thank you, out of curiosity, why is it vastly working throughout my code using the method above?

1 Like

I don’t know, but it’s impossible for the GUI to change on the server side.

1 Like

Are you sure? I’ve got it everywhere in my code and it works perfectly. Here for example, when a player clicks a button it fires the server and this code is ran in a serverscript.

donatePlayer1.OnServerEvent:Connect(function(player)
				if player == losers[1] or player == losers[2] or player == losers[3] then
					player.PlayerGui.DonationPage.Enabled = false
					player.PlayerGui.Donation1.Enabled = true
				end
			end)
			donatePlayer2.OnServerEvent:Connect(function(player)
				if player == losers[1] or player == losers[2] or player == losers[3] then
					player.PlayerGui.DonationPage.Enabled = false
					player.PlayerGui.Donation2.Enabled = true
				end
			end)
			donatePlayer3.OnServerEvent:Connect(function(player)
				if player == losers[1] or player == losers[2] or player == losers[3] then
					player.PlayerGui.DonationPage.Enabled = false
					player.PlayerGui.Donation3.Enabled = true
				end
			end)
1 Like

It is not true. You’re able to enable/disable gui’s for clients directly from the server, but OP should try and give a remote event a try.

I would not recommend changing a player’s gui directly from the server though.

2 Likes

This is the code thats not actually working, as you said I’ll give the remote events a try but if u can spot any issues with this that would be great:

for i = #losers, 1, -1 do
				
				if #winners == 3 then
					losers[i].PlayerGui.DonationPage.Frame.NameFrame.Player1Frame.Visible = true
					losers[i].PlayerGui.DonationPage.Frame.NameFrame.Player2Frame.Visible = true
					losers[i].PlayerGui.DonationPage.Frame.NameFrame.Player3Frame.Visible = true
					losers[i].PlayerGui.DonationPage.Frame.DonateButtonFrame.Player1Button.Visible = true
					losers[i].PlayerGui.DonationPage.Frame.DonateButtonFrame.Player2Button.Visible = true
					losers[i].PlayerGui.DonationPage.Frame.DonateButtonFrame.Player3Button.Visible = true
					losers[i].PlayerGui.Donation1.Frame.Title.Title.Text = winners[1].Name .. "'s Items"
					losers[i].PlayerGui.Donation2.Frame.Title.Title.Text = winners[2].Name .. "'s Items"
					losers[i].PlayerGui.Donation2.Frame.Title.Title.Text = winners[3].Name .. "'s Items"

					losers[i].PlayerGui.DonationPage.Frame.NameFrame.Player1Frame.PlayerName.Text = winners[1].Name
					losers[i].PlayerGui.DonationPage.Frame.NameFrame.Player2Frame.PlayerName.Text = winners[2].Name
					losers[i].PlayerGui.DonationPage.Frame.NameFrame.Player3Frame.PlayerName.Text = winners[3].Name

					local thumbType = Enum.ThumbnailType.HeadShot
					local thumbSize = Enum.ThumbnailSize.Size420x420
					local content1, isReady = Players:GetUserThumbnailAsync(winners[1].UserId, thumbType, thumbSize)
					local content2, isReady = Players:GetUserThumbnailAsync(winners[2].UserId, thumbType, thumbSize)
					local content3, isReady = Players:GetUserThumbnailAsync(winners[3].UserId, thumbType, thumbSize)

					losers[i].PlayerGui.DonationPage.Frame.NameFrame.Player1Frame.PlayerIcon.Image = content1
					losers[i].PlayerGui.DonationPage.Frame.NameFrame.Player2Frame.PlayerIcon.Image = content2
					losers[i].PlayerGui.DonationPage.Frame.NameFrame.Player3Frame.PlayerIcon.Image = content3
				elseif #winners == 2 then
					losers[i].PlayerGui.DonationPage.Frame.NameFrame.Player1Frame.Visible = true
					losers[i].PlayerGui.DonationPage.Frame.NameFrame.Player2Frame.Visible = true
					losers[i].PlayerGui.DonationPage.Frame.DonateButtonFrame.Player1Button.Visible = true
					losers[i].PlayerGui.DonationPage.Frame.DonateButtonFrame.Player2Button.Visible = true
					losers[i].PlayerGui.Donation1.Frame.Title.Title.Text = winners[1].Name .. "'s Items"
					losers[i].PlayerGui.Donation2.Frame.Title.Title.Text = winners[2].Name .. "'s Items"

					losers[i].PlayerGui.DonationPage.Frame.NameFrame.Player1Frame.PlayerName.Text = winners[1].Name
					losers[i].PlayerGui.DonationPage.Frame.NameFrame.Player2Frame.PlayerName.Text = winners[2].Name

					local thumbType = Enum.ThumbnailType.HeadShot
					local thumbSize = Enum.ThumbnailSize.Size420x420
					local content1, isReady = Players:GetUserThumbnailAsync(46202592, thumbType, thumbSize)
					local content2, isReady = Players:GetUserThumbnailAsync(46202592, thumbType, thumbSize)

					losers[i].PlayerGui.DonationPage.Frame.NameFrame.Player1Frame.PlayerIcon.Image = content1
					losers[i].PlayerGui.DonationPage.Frame.NameFrame.Player2Frame.PlayerIcon.Image = content2
				elseif #winners == 1 then
					losers[i].PlayerGui.DonationPage.Frame.NameFrame.Player1Frame.Visible = true
					losers[i].PlayerGui.DonationPage.Frame.DonateButtonFrame.Player1Button.Visible = true
					losers[i].PlayerGui.Donation1.Frame.Title.Title.Text = winners[1].Name .. "'s Items"

					losers[i].PlayerGui.DonationPage.Frame.NameFrame.Player1Frame.PlayerName.Text = winners[1].Name

					local thumbType = Enum.ThumbnailType.HeadShot
					local thumbSize = Enum.ThumbnailSize.Size420x420
					local content1, isReady = Players:GetUserThumbnailAsync(winners[1].UserId, thumbType, thumbSize)

					losers[i].PlayerGui.DonationPage.Frame.NameFrame.Player1Frame.PlayerIcon.Image = content1
				end
				losers[i].PlayerGui.DonationPage.Enabled = true
			end
1 Like

I wouldn’t at all change all that stuff on the server, reason being that if any element is missing due to the player leaving mid-way then the server will error, but if you send a remote event to the client, and the player leaving, no error will occur.

The odds of a player leaving mid-way is close to non-existent, but there is no reason to create such scenarios.

Also your Async can fail, so make sure to wrap them into pcalls.

You should only try to call for the player thumbnail once, whenever they join the game. You then store those thumbnails in a table on the server. When the player leaves the game, you then delete their stored thumbnail from the table. Make sure to have a backup thumbnail to use, for whenever the thumbnail-pcall fails

Here you go:

local backup_thumbnail = "image_string_url"
local player_thumbnails = {}
players.PlayerAdded:Connect(function(player)
	-- Store thumbnail from player that joined
	local content, isReady = pcall(function()
			return players:GetUserThumbnailAsync(player.UserId,Enum.ThumbnailType.HeadShot,Enum.ThumbnailSize.Size150x150)
		end)
	player_thumbnails[tostring(player.UserId)] = (isReady and content) or backup_thumbnail
	
end)
players.PlayerRemoving:Connect(function(player)
	-- Remove stored thumbnail from player that left
	if player_thumbnails[tostring(player.UserId)] then
		player_thumbnails[tostring(player.UserId)] = nil
	end
end)

Sorry if any code-spelling error is in there, I forked bits of it from one of my games.

1 Like

You can change GUIs on the server. It’s just bad practice

Thank you very much, just a quick question, say I wanted to find a specific players thumbnail from the list, how would I do that? Thanks :slight_smile:

If you want the thumbnails to be accessible by the server from multiple scripts, then create a module script with an dictionary of data, where player_thumbnails could be one of the data in there

local module = {
	minimum_something = 3,
	
	players_to_something = 10,

	player_thumbnails = {},-- this way you can fetch the player's thumbnail from the server, in any server script

}
local data_module = require(game.ServerStorage.Data_Module) -- this should be outside any loop/event
local thumbnail = data_module.player_thumbnails[tostring(player.UserId)]
-- We already know if the player is in the game, then they have a thumbnail.
--No matter if it's their real thumbnail or placeholder thumbnail.
--So no need to check
1 Like

Thank you but I have already made a way to move the list to other scripts. What I was wondering is how i would say get “player1”'s thumbnail from the list?

If you know the player, then you know their userId. thus it’s simple just doing

local get_thumbnail = player_thumbnails[tostring(player.UserId)] -- this will give you the thumbnail

In practice it tries to fetch a index in the dictionary, called whatever the userid of the player is.
If no such index is present, then it will return nil.

If you want to make it 100% bulletproof, then check if get_thumbnail is fetched by doing:

local get_thumbnail = player_thumbnails[tostring(player.UserId)] -- this will give you the thumbnail
if get_thumbnail then
-- do something with thumbnail
end
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.