Issue with shop system open and close, not sure why it isnt working

My shop system is a gui that pops up when you talk to an npc. It works when it is first activated, but when I exit the shop and the gui disappear, I cant re enable the gui. Sorry if this is confusing. But anyways the scripts:

Local script in starterplayerscripts

local event = game.ReplicatedStorage.BuyGuns



	workspace.Rob.Head.Dialog.DialogChoiceSelected:connect(function(player,choice)
		if choice.Name == "Yep!" then
			event:FireServer(player)
			print("local worked")

		end

	end)

The server script that receives the remote event located in the npc you talk to:

local event = game.ReplicatedStorage.BuyGuns


function onEvent(player)
	print("server worked")
	local gui = player.PlayerGui:WaitForChild("ShopSystem")
	gui.GunShopCam.Disabled = false
	wait(.5)
	gui.Enabled = true
end

event.OnServerEvent:Connect(onEvent)

So it works the first time, but when I try to re enter the shop the gui doesn’t pop up.

no need to provide the player in here. It automatically does it for you.

also,
instead of wait , use task.wait

1 Like

Yeah, I believe this is the issue too.

1 Like

@drilinz I did what you said but it didn’t work. I remember I put player there because it was erroring, but then I changed stuff around and I just forgot to take that part out.

Did this print out when tested?

Yes it prints the first time, and also the second time.

Any idea on what is wrong?

Do you close the GUI the same way you open it?
(ShopSystem.Enabled)

No I have a text button that disables the gui

2 Likes

@Valkyrop @drilinz any ideas on what is wrong?

1 Like
local replicated = game:GetService("ReplicatedStorage")
local event = replicated:WaitForChild("BuyGuns")

workspace.Rob.Head.Dialog.DialogChoiceSelected:connect(function(player,choice)
	if choice.Name == "Yep!" then
		event:FireServer()
		print("local worked")
	end
end)
local event = game.ReplicatedStorage.BuyGuns


function onEvent(player)
	print("server worked")
	local gui = player.PlayerGui:WaitForChild("ShopSystem")
    if gui then
       print("gui found") -- prints?
       gui.Enabled = false
	   task.wait(0.5)
	   gui.Enabled = true
    end
end

event.OnServerEvent:Connect(onEvent)

Try this

Please notice to the edits I’ve done

1 Like

I had to change the script around a bit to get it to work, but overall it works properly! Thanks!

1 Like