We use cookies on this site to enhance your user experience

Sep 07 2018, 11:03 AM PST

-- Lets players click a button to buy an upgrade that increases MaxSpaces
local buyButton = script.Parent 
local clickDetector = buyButton.ClickDetector

-- Variables for the upgrade
local newSpaces = 10
local upgradeCost = 100

local function giveUpgrade(player)
	print("Someone clicked the button")
	-- Get's the player's leaderboard to get other IntValues
	local playerStats = player:FindFirstChild("leaderstats")
	-- Gets the player's money and spaces to make changes
	local playerGold = playerStats:FindFirstChild("Gold")
	local playerSpaces = playerStats:FindFirstChild("Spaces")
	-- Checks if player has enough money to afford the upgrade
	if playerGold.Value >= upgradeCost then
		print("Player can buy item")
		-- Subtract the item's cost from the player's money
		playerGold.Value = playerGold.Value - upgradeCost
		playerSpaces.Value = newSpaces