How to make a pop-up shop GUI

So here is the first script. This is the shop script that my friend uses, but the one thing that isn’t working is in the bottom,

mon = Player.leaderstats.Wallet
						if mon.Value >= Guns[CurrentValue].Amount then
							mon.Value = mon.Value - Guns[CurrentValue].Amount```
And the first mon has a blue underline(error underline for me). I have a separate leaderstats script, 1 is an autogiver after a specified amount of time, the other is the actual leaderstats script. Those will be listed below the main script.



```local GamePass = 0
local CurrentGroup = 0
local Guns = {
	["AR Pistol"] =  {
		Amount = 10000;
		Image = 0;
	};
	["AR Rifle"] =  {
		Amount = 15000;
		Image = 0;
	};
	["Tec-9"] =  {
		Amount = 10500;
		Image = 0;
	};
	["Colt Pistol"] =  {
		Amount = 10;
		Image = 0;
	};
	["Glock"] =  {
		Amount = 30000;
		Image = 0;
	};
}

Comma = function(x)
	local a = x
	while true do  
		a, k = string.gsub(a, "^(-?%d+)(%d%d%d)", '%1,%2')
		if k == 0 then break end
	end
	return a
end

script.Parent.Touched:connect(function(Part)
	local Player = game.Players:GetPlayerFromCharacter(Part.Parent)
	spawn(function()
	if Player then
		if not Player.PlayerGui:FindFirstChild("GunGui") then
			local CurrentValue = ""
				for i, v in next, Guns do CurrentValue = i break end
			local Gui = script.Parent.GunGui:Clone()
			Gui.Parent = Player.PlayerGui
			local Holder = Gui.Holder
			local ScrollingFrame = Holder.ScrollingFrame
				local HowMany = 0
				for i, v in next, Guns do HowMany = HowMany + 1 end
				ScrollingFrame.CanvasSize = UDim2.new(0,0,0,5 + (35 * HowMany))
			local Buy = Holder.Buy
				Buy.MouseButton1Down:connect(function()
					if Player:IsInGroup(CurrentGroup)
						then
						mon = Player.leaderstats.Wallet
						if mon.Value >= Guns[CurrentValue].Amount then
							mon.Value = mon.Value - Guns[CurrentValue].Amount
					
						game.ServerStorage:FindFirstChild(CurrentValue):Clone().Parent = Player.Backpack
						end
						end
				end)
			local Close = Holder.Close
				Close.MouseButton1Down:connect(function() Gui:Destroy() end)
			local Thumbnail = Holder.Thumbnail
			local Amount = Holder.Amount
			local GunName = Holder.GunName
			Switch = function()
				Thumbnail.Image = "http://www.roblox.com/asset/?id=" .. Guns[CurrentValue].Image
				Amount.Text = "$" .. Comma(Guns[CurrentValue].Amount)			
				GunName.Text = CurrentValue
			end
			Switch()
			local Count = 0
			for i, v in next, Guns do
				local Sample = Instance.new("TextButton", ScrollingFrame)
				Sample.Name = i
				Sample.Position = UDim2.new(0, 5, 0, 5 + (35 * Count))
				Sample.Size = UDim2.new(0, 130, 0, 30)
				Sample.BackgroundColor3 = Color3.new(0, 0, 0)
				Sample.BorderSizePixel = 0
				Sample.Text = i
				Sample.Font = Enum.Font.SourceSans
				Sample.FontSize = Enum.FontSize.Size14
				Sample.TextColor3 = Color3.new(1, 1, 1)
				Sample.MouseButton1Down:connect(function()
					CurrentValue = i
					Switch()
				end)
				Count = Count + 1
			end
		end
	else
		game:GetService("MarketplaceService"):PromptPurchase(Player, GamePass)
	end
	end)
end)

--[[
	~                 ~
	Written
			By
				Bassics
	~                 ~
--]]

AutoCashGiverScript:

```amount = 50
timedelay = 120
currencyname = "Wallet"

while true do
	wait(timedelay)
	for i,v in pairs(game.Players:GetPlayers()) do
		if v:FindFirstChild("leaderstats") then
			v.leaderstats[currencyname].Value = v.leaderstats[currencyname].Value + amount
		end
	end
end

Main Leaderstats Script: (leaderstats name value is Wallet)

 
game.Players.PlayerAdded:Connect(function(plr)
    local leaderstats = Instance.new("Folder", plr)
    leaderstats.Name = "leaderstats"
 
    local Wallet = Instance.new("IntValue", leaderstats)
    Wallet.Name = "Wallet"
    Wallet.Value = DataStore:GetAsync(plr.userId) or 0
 
    Wallet.Changed:Connect(function()
        DataStore:SetAsync(plr.userId, Wallet.Value)
    end)
end)
 
game.Players.PlayerRemoving:Connect(function(plr)
    DataStore:SetAsync(plr.userId, plr.leaderstats.Points.Value)
end)```
The shop GUI works and pops up, its just the buy button that isn't functioning correctly. There is another GUI linked with the top script, the GUI script, and the GUI works but when I try to buy it just doesn't do anything. I have the money and everything I waited the 2 minutes set for that variable, and it still isn't working. I know its something with the leaderstats script being linked with the mon variable, so please help and I am all ears!

Thanks!
2 Likes

Have you debugged the concerned conditions yet?

Buy.MouseButton1Down:connect(function()
    print("Clicked")
    if Player:IsInGroup(CurrentGroup) then
        mon = Player.leaderstats.Wallet
        print("Value:", mon.Value)
        if mon.Value >= Guns[CurrentValue].Amount then
            print("Passed condition...")
            mon.Value = mon.Value - Guns[CurrentValue].Amount
            game.ServerStorage:FindFirstChild(CurrentValue):Clone().Parent = Player.Backpack
            print("Parented tool")
        end
    end
end)
Some comments
  • Please indent your code properly and format it in separate codeblocks:
    ```lua
    print("Hello world”)
    ```

  • mon is underlined as it is a global variable, defining it as local mon should fix the warning.

  • Don’t use Instance.new() with parent argument

Here are some recommendations:

  1. If you are changing the player’s money from a LocalScript, on the client, remember that thanks to Filtering Enabled, these changes are not seen by the server. To solve this, you must use a pair of RemoteEvents and RemoteFunctions.
  2. Also remember that if you are checking that the player has enough money to buy the product, from the client, the exploiters, unfortunately, can easily pass this check and get the product for free.
  3. You can also use StarterGear to give items to users. I recommend you to clone the tool in the Backpack and StarterGear. (Although there is almost no difference)
  4. And finally, if you are cloning the item from a LocalScript, change it and do everything from the server. As I mentioned earlier, all this can be solved with a pair of RemoteEvents and RemoteFunctions.

Let me know if you need more help, I can send you a script explaining how to do all this from the server.

So scale a part to the area size you want the player to step into. Then can collide off, also set the transparency to 1. Follow scripts from other replies