SurfaceGui Doesn't work

im creating a barrier for my game that you can unlock using coins but the surface gui doesn’t work

Barrier_handler (player side)

local Barriers = workspace.Barriers

function PromptSetup(promptBill, prompt)
	promptBill.Frame.InputFrame.Frame.ButtonText.Text = prompt.KeyboardKeyCode
	promptBill.Frame.TextFrame.ActionText.Text = prompt.ActionText
	promptBill.Frame.TextFrame.ObjectText.Text = prompt.ObjectText
end

function PromptNew(barrier)
	local prompt = barrier.PrimaryPart.PromptAttach.Prompt
	local promptBill = barrier.PrimaryPart.PromptAttach.PromptBill
	
	PromptSetup(promptBill)
	
	prompt.PromptShown:Connect(function()
		promptBill.Enabled = true
	end)
	
	prompt.PromptHidden:Connect(function()
		promptBill.Enabled = false
	end)
end

function Setup(barrier)
	barrier = Barriers["Fungus Forest"] -- this will be barrier value
	local Gui = barrier:FindFirstChild("Blocker").SurfaceGui
	Gui.Frame.Price.Text = barrier.PrimaryPart.Price.Value
	Gui.Enabled = true
	Gui.Frame.DimensionName.Text = barrier.Name
end

for i, barrier in pairs(Barriers:GetChildren()) do
		Setup(barrier)
		PromptNew(barrier)
end

here how it was going to work:
image

and the error:

if someone knows please comment
everything helps! :smiley:

1 Like

check the PromptSetup parameter

function PromptNew(barrier)
local prompt = barrier.PrimaryPart.PromptAttach.Prompt
local promptBill = barrier.PrimaryPart.PromptAttach.PromptBill

PromptSetup(promptBill) -- right here

prompt.PromptShown:Connect(function()
	promptBill.Enabled = true
end)

prompt.PromptHidden:Connect(function()
	promptBill.Enabled = false
end)

end

function Setup(barrier)
barrier = Barriers[“Fungus Forest”]
local Gui = barrier:FindFirstChild(“Blocker”).SurfaceGui
Gui.Frame.Price.Text = barrier.PrimaryPart.Price.Value
Gui.Enabled = true
Gui.Frame.DimensionName.Text = barrier.Name
end

for i, barrier in pairs(Barriers:GetChildren()) do
Setup(barrier)
PromptNew(barrier)
end

but the error is:
Players.matolol2011.PlayerScripts.Barriers_Handler:26: attempt to index nil with 'SurfaceGui'
not the promptBill (promptBillboard: custom proxymity prompt)

and i even tried to print the barrier:FindFirstChild("Blocker") and barrier:WaitForChild("Blocker") and prints Nil

check if the SurfaceGui is there (while playing, check if the surface GUI is existed)

i tried having the surface gui enabled on testing and same result error because is Nil

OK maybe you can also check if each barrier has a SurfaceGui

here the model
image
is in the blocker but is error

ps: the barriers folder is in workspace

and for before the prompt function was functioning very well

change each function into a local function maybe it will work now
or you can add :WaitForChild()

the first line nil is the test for searching barrier:FindFirstChild(“Barrier”)

ok I recommend using a :WaitForChild() - this function is always used when some things are not loaded yet after play testing, :FindFirstChild() - use this if there are some script that can removing it occasionally

  15:26:59.283  Infinite yield possible on 'Workspace.Barriers.Fungus Forest:WaitForChild("Blocker")'  -  Studio
  15:26:59.283  Stack Begin  -  Studio
  15:26:59.284  Script 'Players.matolol2011.PlayerScripts.Barriers_Handler', Line 27 - function Setup  -  Studio - Barriers_Handler:27
  15:26:59.284  Script 'Players.matolol2011.PlayerScripts.Barriers_Handler', Line 34  -  Studio - Barriers_Handler:34
  15:26:59.284  Stack End  -  Studio

WHAT it kinda works but it gave the error up above

1 Like

ok try to put this one

Workspace:WaitForChild(“Barriers”):WaitForChild(“Fungus Forest”):WaitForChild(“Blocker”)

this could be the key to solve it

but uhh
line 1
local Barriers = workspace.Barriers

line 33

for i, barrier in pairs(Barriers:GetChildren()) do
		Setup(barrier)
		PromptNew(barrier)
end

line 27
local Gui = barrier:WaitForChild("Blocker").SurfaceGui

the thing is this :sweat_smile:

oop forgot one part

yeah thats fine but you can add like this

local Barriers = workspace:WaitForChild(“bla bla bla”) and so on

but uhh
line 1
local Barriers = workspace.Barriers

line 27
local Gui = barrier:WaitForChild("Blocker").SurfaceGui

line 33

for i, barrier in pairs(Barriers:GetChildren()) do
		Setup(barrier)
		PromptNew(barrier)
end

the thing is this :sweat_smile:

in line 1 - lacking of :waitforchild()
in line 27 - same

in reality line 27 has waitForChild :sweat_smile:
but it doesn’t work
and if it was line 1 the script was going to stop right away

in line 27, check if before the “SurfaceGui” has a :waitforchild()