I am making a game in Roblox and I came across an error. I am trying to make gui button that opens the shop in the game. But it does not open.
I\'v tried to make the but
Your issue is that you're accessing the object from the StarterGui service. StarterGui clones its contents into the player's PlayerGui folder once the player loads. Thus, you need to access the object from there. To do this, we'll use a LocalScript and access the folder through the LocalPlayer object. As a note, LocalScripts can only run in places, which are direct descendants of the player, like StarterPack, StarterPlayerScripts, StarterCharacterScripts, or StarterGui.
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local gui = player:WaitForChild("PlayerGui"):WaitForChild("ShopSelection") --wait for objects
local button = player.PlayerGui:WaitForChild("Shop") --:WaitForChild() yields the thread until the given object is found, so we don't have to wait anymore.
button.MouseButton1Down:Connect(function()
gui.Visible = true
button.Visible = false
end)
Hope this helps!