Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Shop Gui using leaderstats?

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

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)

3 comments

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?

0

create a liderstats folder

0

leader

This discussion is preserved as it was. New answers, comments, and votes are closed.