Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Shop Gui using leaderstats?

Asked by 4 years ago

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.

1 answer

Log in to vote
0
Answered by 4 years ago

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)
0
It is still not working and i'm getting the same error message and now the gui is not showing up, so do you have any other ideas or should I try to make a shop another way? EyeDontLie 2 — 4y
0
create a liderstats folder alexfinger21 341 — 4y
0
leader alexfinger21 341 — 4y
Ad

Answer this question