My GUI isn't displaying on the screen

Hi, for some reason a gui isn’t appearing on the players screen. Any ideas why?

local function disconnectConnections(kills, loserPlayer)
				if kills == 5 then
					for i, v in ipairs(connections) do
						v:Disconnect()
					end

					if plr1CurrentKills == 5 then
						winner = player1
						loser = loserPlayer
					elseif plr2CurrentKills == 5 then
						winner = player2
						loser = loserPlayer
					end			

					player1.RespawnLocation = game.Workspace.SpawnLocs.SpawnLocation1
					player2.RespawnLocation = game.Workspace.SpawnLocs.SpawnLocation1
					
					if winner == player1 then
						for index,player in pairs(Players:GetPlayers()) do --Get all the players in the game
							--player is the player we are currently at
							--index is not used and mostly used for tables (don't get confused here, we don't use index in this script)
							local possibleTool = player1.Backpack:FindFirstChild("Sword")
							local possibleTool1 = player1.Character:FindFirstChild("Sword")

							if possibleTool then --if the tool is in the backpack
								possibleTool:Destroy()
							elseif possibleTool1 then --if it's equipped
								possibleTool1:Destroy()
							end
						end
					elseif winner == player2 then
						for index,player in pairs(Players:GetPlayers()) do --Get all the players in the game
							--player is the player we are currently at
							--index is not used and mostly used for tables (don't get confused here, we don't use index in this script)
							local possibleTool = player2.Backpack:FindFirstChild("Sword")
							local possibleTool1 = player2.Character:FindFirstChild("Sword")

							if possibleTool then --if the tool is in the backpack
								possibleTool:Destroy()
							elseif possibleTool1 then --if it's equipped
								possibleTool1:Destroy()
							end
						end
					end
					
					winner.leaderstats.Wins.Value += 1
					winner.leaderstats.Winstreak.Value += 1
					loser.leaderstats.Winstreak.Value = 0
					
					local function getUserGeneratedTShirtsRecursive(username, tshirts, cursor)
						tshirts = tshirts or {}
						cursor = cursor or ""
						local requestUrl = baseUrl:format(username, cursor)
						local success, result = pcall(function()
							return http:GetAsync(requestUrl)
						end)

						if success then
							if result then
								local success2, result2 = pcall(function()
									return http:JSONDecode(result)
								end)

								if success2 then
									if result2 then
										for _, tshirt in ipairs(result2.data) do
											table.insert(tshirts, tshirt.id)
										end

										cursor = result2.nextPageCursor
										if cursor then
											return getUserGeneratedTShirtsRecursive(username, tshirts, cursor)
										else
											return tshirts
										end
									end
								else
									warn(result)
								end
							end
						else
							warn(result)
						end
					end
					
					loser.PlayerGui.Donation.Enabled = true -- THIS IS THE PART THAT SHOULD MAKE IT VISIBLE

					local username = winner.Name
					local userTShirts = getUserGeneratedTShirtsRecursive(username)
					local num = (#userTShirts) 
					print(table.concat(userTShirts, " ")) --1031862 1036727 1031864
					
					game.ReplicatedStorage.RemoteEvent:FireClient(winner)

					winner.PlayerGui.Donation.Frame.TextLabel.Text = "Donate to ".. username
					
					local table1 = {}
					
					for i = num, 1, -1 do
						local Asset = MarketPlaceService:GetProductInfo(userTShirts[i])
						local assetPrice = Asset.PriceInRobux
						local assetId = Asset.AssetId
						
						if assetPrice == nil or assetId == nil then
							print("Failure")
						else 
							-- Create a new table for each item with the price and id
							local item = {price = assetPrice, id = assetId}

							-- Insert the item into the table
							table.insert(table1, item)
						end

						-- Create a new table for each item with the price and id
						
					end
					
					table.sort(table1, function(a, b)
						return a.price < b.price
					end)

					for i, item in ipairs(table1 or {}) do
						if item then
							local price = item.price or "default price"
							local id = item.id or "unknown"
							
							local newButton = workspace.DonateButton:Clone()
							newButton.Text = price .. " R$" 

							local id = Instance.new("IntValue", newButton)
							id.Value = item.id

							newButton.Parent = winner.PlayerGui.Donation.Frame.itemsScroller
							
						else
							
						end
					end					

The line that should make it visible is on line 86.

Sorry for the long script but thought u might need it to see the issue.

Edit: I think the issue is something to do with my variable for ‘loser’ as when its ‘winner’ it displays on their screen perfectly fine. The ‘loser’ died so I dont know if that messes up the variable or something, so here is the part of the script where I pass the variable into the disconnectConnections function.

connections[1] = player1.CharacterRemoving:Connect(function(hit)

				char1 = nil
				char2 = nil

				char1 = player1.Character
				char2 = player2.Character

				local player1 = game.Players:GetPlayerFromCharacter(char1)

				local humanoid1 = char1.Humanoid

				plr2CurrentKills = plr2CurrentKills + 1

				game.Workspace["Sword Fighting Arenas"].Arena1.Monitor.Surface.MainFrame.Main.score_t1.Text = plr1CurrentKills
				game.Workspace["Sword Fighting Arenas"].Arena1.Monitor.Surface.MainFrame.Main.score_t2.Text = plr2CurrentKills
				game.Workspace["Sword Fighting Arenas"].Arena1.Monitor.Surface2.MainFrame.Main.score_t1.Text = plr1CurrentKills
				game.Workspace["Sword Fighting Arenas"].Arena1.Monitor.Surface2.MainFrame.Main.score_t2.Text = plr2CurrentKills

				if disconnectConnections(plr2CurrentKills, player1) then return end

Could you send only what doesn’t work as I’m completely lost.

1 Like

‘loser.PlayerGui.Donation.Enabled = true’

But I don’t think the issue is this line, I think its the value of ‘loser’ that has an issue.

So basically the issue is that the line DOES work but the UI gets reset because of the player dying. To fix this you can:

Try disabling resetonspawn in startergui->yourscreengui. This will make it so the ui stays and does not reset. This might interfere with your specific game type though.

1 Like

Thanks for your help, its all fixed :slight_smile:

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