¿Gui not enabling?

Hello developers

I’m need to make a Gui enable, but for some reason, it doesn’t work.

This is the important part of the code:

for i,BuyButtonGui in pairs(game.StarterGui.LevelGuis:GetChildren()) do
			if BuyButtonGui.Adornee == BuyButton.Next.Value then -- Next is the next button to buy the next level
				BuyButtonGui.Enabled = true
			end
		end

It’s a server script.

Here it’s a video of the issue:


It would be supposed to enable the gui of that part, but it doesn’t.

If you need the entire code or more explanation, tell me.

Thanks in advance :slightly_smiling_face:

I think the issue is that you are trying to access StarterGui instead of PlayerGui. Use PlayerGui instead.

I am not sure if you got the player, but the code should look something like this:

for i,BuyButtonGui in pairs(player.PlayerGui.LevelGuis:GetChildren()) do
			if BuyButtonGui.Adornee == BuyButton.Next.Value then -- Next is the next button to buy the next level
				BuyButtonGui.Enabled = true
			end
		end

But I believe you should actually use remote events in this situation.

mistake one. dont use startergui, its playergui.

local Players = game:GetService("Players")
local clientPlayer = Players.LocalPlayer
local PlayerGui = clientPlayer.PlayerGui

Yeah, i tried with PlayerGui but it doesn’t works.

I think that it’s because i’m trying to enable a SurfaceGui with an Adornee to a part.

If it helps this is the entire code:


local RS = game:GetService("ReplicatedStorage")
local BuyLevel = RS:WaitForChild("BuyLevel")

BuyLevel.OnServerEvent:Connect(function(player, Level, Cost,BuyButton,ButtonGui)
	if player:WaitForChild("Values").Money.Value >= Cost then
		
		player:WaitForChild("Values").Money.Value -= Cost
		
		BuyButton.Transparency = 1
		ButtonGui.Enabled = false
		
		if game.Workspace.LevelButtons:FindFirstChild(BuyButton.Next.Value) then
			game.Workspace.LevelButtons:FindFirstChild(BuyButton.Next.Value).Transparency = 0
		else
			return
		end
		
		for i,BuyButtonGui in pairs(player.PlayerGui.LevelGuis:GetChildren()) do
			if BuyButtonGui.Adornee == BuyButton.Next.Value then -- Next is the next button to buy the next level
				BuyButtonGui.Enabled = true
			end
		end
		
		for i,Children in pairs(game.Workspace.Levels:FindFirstChild(Level):GetChildren()) do
			if  Children.Name == "ClaimMoney" then
				Children.Transparency = 0.4
				Children.BillboardGui.Enabled = true
				Children.CanCollide = false
			elseif Children:IsA("Model") then
				for i,ModelChildren in pairs(Children:GetChildren()) do
					ModelChildren.Transparency = 0
					ModelChildren.CanCollide = true
					
					if ModelChildren.Name == "Truss" then
						ModelChildren.Transparency = 1
					end
				end
			else
				
				Children.Transparency = 0
				Children.CanCollide = true
			end
		end
		
	else
		print("Not enough money to buy the: "..Level)
	end
end)

Look at the other post that i did

There’s several ways to get the ScreenGui, here’s the three best methods, they depend on where the script is located.

-- if the script resides in LevelGuis
local levelguis = script:FindFirstAncestor("LevelGuis")
for _, v in pairs(levelguis:GetChildren()) do

end

-- if the script resides in another screen gui
local playergui = script:FindFirstAncestorWhichIsA("PlayerGui")
for _, v in pairs(playergui:WaitForChild("LevelGuis"):GetChildren()) do

end

-- if the script isn't in a gui content container
local players = game:GetService("Players")
local player = players.LocalPlayer
local playergui = player:FindFirstChildWhichIsA("PlayerGui")
for _, v in pairs(playergui:WaitForChild("LevelGuis"):GetChildren()) do

end

Actually this is a script for buying the obby levels, inside the ServerScriptService
image
It works with a RemoteEvent by the way.

And this is the part of the SurfaceGuis
image

Inside of those guis, there are local scripts like this:

script.Parent.TextButton.MouseButton1Click:Connect(function()
	game.ReplicatedStorage.BuyLevel:FireServer("Level 1",0,game.Workspace.LevelButtons.BuyLVL1Button,script.Parent)
end)

I have a system to when you join, all the levels are going to be transparent and the Guis too, so i want that when you buy the first level, the second button to buy the next level, get visible, but i can’t achieve to make the Gui visible for some reason, tell me if you need more info.

I’d probably use a RemoteFunction for that, then you can get a response from the server and make your changes depending on that response.

But why? if i need to enable the gui from the server

Why handle the UI from the server when you can replace the RemoteEvent with a RemoteFunction, call the server for information with it, and then proceed to make changes on the client once more?