Why is my shop gui not popping up?

When i click on the dummy. For some reason the shop gui doesn’t seem to show. I thought I had all my code in there correctly.

shopScript(the script that is in the click detector for the dummy):


script.Parent.MouseClick:Connect(function()
	if shopGui.Visible == false then
		shopGui.Visible = true
		
	end
	
end)

The dummy I want to use it on.

Here is what the layout looks like:

image

Thank you.

4 Likes

How are you defining shopGui?

Probably because you’re trying to get a local gui to pop up via a server script?

oh sorry forgot to add this:

local shopGui = script.Parent.Parent.Parent.Parent.StarterGui.ShopGui.Frame
2 Likes

I’d say that whatever that line of parents are is the cause of the problem.

I suggest using the first parameter of the MouseClick event, found here: ClickDetector | Documentation - Roblox Creator Hub

The first parameter is a Player instance, so you can just use something like:

script.Parent.MouseClick:Connect(function(Player)
	if Player.StarterGui.shopGui.Visible == false then
		Player.StarterGui.shopGui.Visible = true
		
	end
	
end)

Hi.
You have to reference ShopGui inside the PlayerGui not the StarterGui. If you are using a local script, then the code should be:

local shopGui = game.Players.LocalPlayer.PlayerGui.ShopGui

1 Like

it’s not a local script. Sorry i should have specified that

Please don’t do this. ClickDetectors can be connected to from the client as well. If everything here is client-based, you should be handling all this logic from the client.

The server has no reasons to waste resources facilitating this interaction.

4 Likes

@TheCarbyneUniverse @roseblade578
There isn’t much point involving the server for this sort of thing unless it is crucial that you have to. The servers memory should be saved for things like DataStores, Matchmaking ect. This brings me onto say that it is possible to make this whole system client sided with not many changes.


First you will need to create a LocalScript and place it anywhere on the client, preferably in StarterGui in the shop GUI. Here is a little image of the setup below:
Shop%20Setup%20(2)

Once you have a setup similar to that you will need to put the code into the LocalScript. I have tweaked your code slightly to make it work client sided as shown below:

local ShopPart = workspace.Shop -- Where the shop is located in workspace

ShopPart.ClickDetector.MouseClick:Connect(function()
	if not script.Parent.Frame.Visible then
		script.Parent.Frame.Visible = true
	end
end)

Here is the shop setup in workspace
Shop%20Setup%20workspace%20(2)

4 Likes

Thanks! got this to work! I thought for some reason I had to put the click detector code in the actual shop part itself, not the starterGui.