-
What do you want to achieve?
I want to make my Shop GUI allow me to buy a tool -
What is the issue?
When I buy my tool it says I do not have enough but I do.
-
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)