So I tried making a script where when you interact with an npc a gui appears but it keeps showing me this error in the Output.

Here's the script :

1  local TemplatesPart = script.Parent
2  local Temp = game.Workspace.Templates
3
4  TemplatesPart.ProximityPrompt.Triggered:Connect(function(player)
5	local open = false
6	local PlayerGui = player:WaitForChild("PlayerGui")
7	local ScreenGui = PlayerGui:WaitForChild("ScreenGui", 1)
8	local Frame = ScreenGui.Frame
9	
10	if open == false then
11		open = true		
12		Frame.Visible = true
13	else
14		open = false
15		Frame.Visible = false
16
17	    end
18  end)

9 comments

0

try debugging with a print. On line 9 you can put if PlayerGui:FindFirstChild("Frame") then print("working") end

0

I tried and still says Workspace.Templates.Torso.Attachment.Prompt:8: attempt to index nil with 'Frame'

0

If you check the output does it print "working"?

0

Nope.

0

Alright, in that case the problem is that you aren't setting the Variable correctly. Check workspace and make sure that you have Frame parented to the ScreenGui. Also make sure that the frame is named "Frame".

1

Somehow it started working again! I think it was because the ScreenGui was named 'shop'?

0

Thank you!

0

No problem. If you're confused as to why that wouldn't work, I believe its because you set local ScreenGui to PlayerGui:WaitForChild("ScreenGui"). This means that the value will be nil if the ScreenGui was named "Shop"

0

Ooooh I get it now.