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

Surface Gui Shop Script not working? -(ANSWERED)

Asked by 10 years ago

Could I get some help with my script? I made a surface Gui shop using Coins as money but when I click the button it doesn't give me my item or spend the Coins for it. here's the script

repeat wait()
Player = game.Players.LocalPlayer
Button = script.Parent
Item = game.ReplicatedStorage:FindFirstChild("BloxyCola")
Cost = 25
Coin = Player.leaderstats.Coins
until

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

Oh and here's where the script is. (Sign.SurfaceGui.TextButton.LocalScript)

1 answer

Log in to vote
0
Answered by 10 years ago

First, I suggest you use MouseButton1Click. As far as I know, both events don't return anything, so purchase = nil. StarterGear is not part of a player. That's only in Studio.

Cost = 1
Item = game.ReplicatedStorage.BloxyCola
Button.MouseButton1Click:connect(function()
game.Players.LocalPlayer.leaderstats.Coins.Value = game.leaderseats.Coins.Value - Cost
Item:Clone().Parent = game.Players.LocalPlayer.Backpack
end)
-- this should work now
0
Thanks, it works now. Armoredtj 25 — 10y
0
No problem fahmisack123 385 — 10y
Ad

Answer this question