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

Why Won't My Shop Gui Work?

Asked by 8 years ago

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)
0
I can see an error on line 2 in the second script. Notice the extra dot. NeonicPlasma 181 — 8y

2 answers

Log in to vote
0
Answered by 8 years ago

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.

Ad
Log in to vote
0
Answered by
FiredDusk 1466 Moderation Voter
8 years ago

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)

Answer this question