Why does ui not show when enabled?

Hello, so basically i have setup a system that on a product purchase ui shows. When the screengui is enabled on game start up it shows. However after the game has loaded and then enabled, it doesn’t show.

Video:

2 Likes

Can you show the script?
I think it’s because you’re enabling the GUI in StarterGui. Try enabling it in PlayerGui instead.

Yeah, i am enabling it in StarterGui. How would i enable it in PlayerGui?

Do game:GetService("Players").LocalPlayer.PlayerGui.ScreenGui.Enabled = true

Nope, Didn’t work. I will show you my code. (Be prepared for a mess)

local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")

local ServerStorage = game:GetService("ServerStorage")
local Debris = game:GetService("Debris")

local TeamNameToGiveToolsTo = "Class-D" -- The name of the team that you want to give the tools to
local Id = 1163707338 -- Your productId here
local Time = 5 * 60 -- 5 minutes the tool is given for.
local rep = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")
local minutesvalue = rep:WaitForChild("Minutes")
local secondsvalue = rep:WaitForChild("Seconds")
local minutes = 5 --minutes (For the timer)
local seconds = 0 --seconds (For the timer)

local Tools = game.ReplicatedStorage.Tools -- The path to your folder with all of the tools in it

local function GiveTools()
	for i, Player in Players:GetPlayers() do
		if Player.Team.Name == TeamNameToGiveToolsTo then
			for i, Tool in Tools:GetChildren() do
				local NewTool = Tool:Clone()
				NewTool.Parent = Player.Backpack

				Debris:AddItem(NewTool, Time)
			end
		end
	end
end

local function HandlePurchase(receiptInfo)
	local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
	local productId = receiptInfo.ProductId
	if player and productId == Id then
		GiveTools()
		game:GetService("Players").LocalPlayer.PlayerGui.ScreenGui.Enabled = true
		
		
		minutesvalue.Value = minutes
		secondsvalue.Value = seconds

		repeat
			if secondsvalue.Value <= 0 then
				minutesvalue.Value = minutesvalue.Value - 1
				secondsvalue.Value = 59
			else
				secondsvalue.Value = secondsvalue.Value - 1
			end
			wait(1)
		until secondsvalue.Value <= 0 and minutesvalue.Value <= 0
		
		
		return Enum.ProductPurchaseDecision.PurchaseGranted
		
	else
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
end



MarketplaceService.ProcessReceipt = HandlePurchase






The issue is that you try to change the property in the StarterGui UI instead of the PlayerGui one. When a user is added to the game or resets all the UIs and scripts in StarterGui are copied to PlayerGui which is located inside the Player instance. So all you have to do is fetch the player instance and change that instead. Using something like LocalPlayer will only work for LocalScripts but not Scripts(server scripts). For server scripts to fetch the player you have to use other methods and for your use case you have already done so(the player variable in your code). So replace the game:GetService("Players").LocalPlayer part of your code with just player(basically player.PlayerGui.ScreenGui.Enabled = true).

4 Likes

Will give this a go and let you know of the results.

Thanks, this works. :slight_smile:

How would I tween it on screen?

Also, the Ui only shows for one person in the game not all of them.

Fire a RemoteEvent to all the clients that enable their ScreenGui when recieved

1 Like

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