Help with Shop GUI

  1. What do you want to achieve?
    I want to make my Shop GUI allow me to buy a tool

  2. What is the issue?
    When I buy my tool it says I do not have enough but I do.

  3. What solutions have you tried so far?
    I looked at youtube.com and devforum.roblox.com

I am trying to make my shop GUI work but when I buy the tool even if I have 5000 Cash it says I do not have enough. I tried changing the elseif statement and it says it is a boolean but it is not. There is no errors inside my Output.

--ServerScript
local Tools = game.ReplicatedStorage:WaitForChild("Tools")
local prices = {
	["Grapple Gun"] = 200,
	["Laser Gun"] = 350,
	["Fake Knife"] = 525
} -- I saw in an earlier post that you store your prices in TextLabels. This works, but I did not implement it since I'm not sure of the location of this script

game.ReplicatedStorage.Events.BuyItemEvent.OnServerEvent:Connect(function(plr, tool)
	local item = Tools:FindFirstChild(tool) -- This will be nil if the tool does not exist

	if item and plr.leaderstats.Cash.Value >= prices[tool] then -- Checks if the tool exists and if the player has enough money
		item:Clone().Parent = plr.Backpack -- Give player the tool
		plr.leaderstats.Cash.Value = plr.leaderstats.Cash.Value - prices[tool] -- Removes money from the player
		print(plr.Name.." purchased "..tool)
	elseif item then
		print(plr.Name.." does not have enough money to purchase "..tool)
	else
		print("Tool requested by "..plr.Name.." does not exist!")
	end
end)

--LocalScript
local player = game:GetService("Players").LocalPlayer

local remoteEvent = game.ReplicatedStorage:WaitForChild("Events"):WaitForChild("BuyItemEvent")

local function buyItem()
	local toolName = "Grapple Gun" --There is 3 scripts for different buttons
	remoteEvent:FireServer(toolName)
	if player.leaderstats.Cash.Value >= 200 then
		script.Parent.Bought.BackgroundColor3 = Color3.fromRGB(0,255,0)
	end
end

script.Parent.MouseButton1Click:Connect(buyItem)
1 Like

That is my main account it has the wrong birthday so cannot join devforum

Check how you give yourself the cash.

The cash has to be given on the server since you are checking it on the server.

1 Like

Ok :grinning_face_with_smiling_eyes: :grinning_face_with_smiling_eyes:

I did that and it just says I have 0 lol I changed it to 10000 on the server

image

@Chrofex :grinning_face_with_smiling_eyes:

Fixed it ok and lemme check :grinning_face_with_smiling_eyes: