I've been trying to make a GUI shop with my existing leaderstats and it isn't working heres the code. It is inside of a Gui and the script is a script and to test i click run and it prints out that message.
``local player = game.Players.LocalPlayer local money = player.leaderstats.Coins.Value
local rs = game:GetService("ReplicatedStorage") local carridge = rs:WaitForChild("Stagecoach")
if script.Parent.MouseButton1Click then if money < 400 then print("false") script.Parent.Parent:Destroy() end if money >= 400 then local clone = carridge:Clone() clone.Parent = game.Workspace clone.Position = game.Workspace.wagonspawn end end``
and i get this error message: 16:14:53.609 - Players.EyeDontLie.PlayerGui.CarridgeshopGui.Frame.1Button.Script:2: attempt to index nil with 'leaderstats'
I don't know whats wrong and or what to do, Keep in mind im fairly new to scripting.
Hello! There is an easy solution to your problem. Basically, if musebutton1click is a function, not a value. Also, I added the part that will subtract cash. Here:
local player = game.Players.LocalPlayer local money = player.leaderstats.Money script.Parent.MouseButton1Click:Connect(function() if money.Value < 400 then print("false") script.Parent.Parent:Destroy() end if money.Value >= 400 then money.Value = money.Value - 400 local clone = carridge:Clone() clone.Parent = game.Workspace clone.Position = game.Workspace.wagonspawn end end)