Why doesn't this code work?

Hello developers, so I have been working on this code to open a frame in StarterGUI, and when I use the ProximityPrompt in the game, it will print my name, but the GUI I want to show up is not showing up? If anybody would help, I would really appreciate it. The code and all the details you need to know is Just below:
Code:

"local ProximityPrompt1 = script.Parent.ProximityPrompt

local UI = game.StarterGui.PCUI.UI.UIDesign.MainFrame

ProximityPrompt1.Triggered:Connect(function(player)

print(player.Name)

UI.Visible = true

end)"

If anyone needs anymore references, then please tell me and I can get you them.

Thanks a lot!

Edit: I have triple checked that I have referenced my GUI correctly.

local ProximityPrompt1:ProximityPrompt? = script.Parent.ProximityPrompt

ProximityPrompt1.TriggerEnded:Connect(function(player:Player?)

	print(player.Name)

	player.PlayerGui.PCUI.UI.UIDesign.MainFrame.Visible = true

end)

You are using StarterGUI wrong way.

local ProximityPrompt1 = script.Parent.ProximityPrompt

ProximityPrompt1.Triggered:Connect(function(player)
local UI = player.PlayerGui.Whatever

UI.Visible = true

end)
1 Like

Thanks you for the help, I didn’t know about Player GUI. I appreciate the help!

1 Like

The problem is that you’re changing a GUI in StarterGui, not the playerGui.

local ProximityPrompt1 = script.Parent.ProximityPrompt
local UI = game.StarterGui.PCUI.UI.UIDesign.MainFrame

ProximityPrompt1.Triggered:Connect(function(player)
    print(player.Name)
    UI.Visible = true
end)

Whenever the game launches, the items in StarterGui get added to the Player under a folder called PlayerGui. Therefore, you should get the player and then get the Gui from their PlayerGui folder.

local ProximityPrompt1:ProximityPrompt? = script.Parent.ProximityPrompt

ProximityPrompt1.TriggerEnded:Connect(function(player)
	print(player.Name)
	player.PlayerGui.PCUI.UI.UIDesign.MainFrame.Visible = true
end)
1 Like

NP, it’s just a replica of ScreenGUI in your player. If you ever use TweenService, you need to use the PlayerGUI.

1 Like

I will keep that in mind for the future, as I plan to add Tweening LOL. Thanks again!

1 Like

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