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

Surface Gui Shop Script not working? -(ANSWERED)

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

✓ Accepted answer

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

2 comments

0

Thanks, it works now.

0

No problem

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