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

Why Won't My Shop Gui Work?

I've made a leaderboard with the money and i've tried to make it a keydown event. And it didnt work even if i've had enough.

Leaderboard Script

game.Players.PlayerAdded:connect(function(p)
	local stats = Instance.new("IntValue")
	stats.Name = "leaderstats"
	stats.Parent = p
	
	local money = Instance.new("IntValue")
	money.Name = "CryptBux"
	money.Value = 500
	money.Parent = stats
end)

GUI Item Purchasing Local Script

repeat wait()
Player = Game.Players.LocalPlayer.
Button = script.Parent
Item = game.ReplicatedStorage:FindFirstChild("Benelli M3")
Cost = 500
Money = Player.leaderstats.CryptBux
until

Button.KeyDown(t):connect(function(purchase)
	if Money.Value > (Cost - 1) then
		Money.Value = Money.Value -
		local a = Item:Clone()
		a.Parent = Player.Backpack
		local b = Item:Clone()
		b.Parent = Player.StarterGear
	end
end)

1 comment

0

I can see an error on line 2 in the second script. Notice the extra dot.

2 answers

I noticed three issues with the second script:

Player = Game.Players.LocalPlayer.
Button = script.Parent
Item = game.ReplicatedStorage:FindFirstChild("Benelli M3")
Cost = 500
Money = Player.leaderstats.CryptBux

Button.KeyDown:connect(function(key)
    if Money.Value > (Cost - 1) then
        Money.Value = Money.Value - Cost
        local a = Item:Clone()
        a.Parent = Player.Backpack
        local b = Item:Clone()
        b.Parent = Player.StarterGear
    end
end)

The first was on line 9, where you had (t)after KeyDown.

The second was that you weren't subtracting anything from Money.Value; here we are subtracting Cost

The third was the repeat loop, since it both was unnecessary and preventing the running of the script.

The guy before me messed up, he did not fix 1 more error.

Player = Game.Players.LocalPlayer --They had a "." here. (FIXED NOW!)
Button = script.Parent
Item = game.ReplicatedStorage:FindFirstChild("Benelli M3")
Cost = 500
Money = Player.leaderstats.CryptBux

Button.KeyDown:connect(function(key)
    if Money.Value > (Cost - 1) then
        Money.Value = Money.Value - Cost
        local a = Item:Clone()
        a.Parent = Player.Backpack
        local b = Item:Clone()
        b.Parent = Player.StarterGear
    end
end)

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