I am creating a small restaurant in Roblox, and was working on the GUI to purchase your food. My original code had quite a few errors so I decided to watch some tutorials to see what I missed. I ended up with the following code:
script.Parent.MouseButton1Click:connect(function()
local RS = game:GetService("ReplicatedStorage")
local item = RS:WaitForChild("FishKabob")
local price = 5 -- Change Your Price Here
local player = game.Players.LocalPlayer
local stats = player:WaitForChild("leaderstats")
print("good day")
if stats.Coins.Value >= price then -- Change the Money to your Currency Name
print("hello")
stats.Coins.Value = stats.Coins.Value - price
local cloned = item:Clone()
local cloned2 = item:Clone()
cloned2.Parent = player.Backpack
cloned.Parent = player.StarterGear
end
end)
Please ignore the prints, I was trying to figure out how far the code went. The prints never showed up, but instead I got this error message.
attempt to index local 'player' (a nil value)
Could anyone help me fix this code so when I click on my GUI Image Button, it gives the kabob and removes 5 coins from the player's leaderstats/currency?
