Now we will program the BuyScript so we can buy more spaces for our items.
Start on line 17 and copy the code from the image until they are matching.
Line 17 connects our ClickDetector to our Shop.
Under Line 17 write print(“Someone clicked the button”) to print a sentence.
Create two local variables on lines 19 and 20.
The code on lines 19 and 20 gets the gets the player’s money and spaces to make changes
Create an If Then Statement
An if then statement asks if something is true, then do something. The if is a condition and whatever we put after then is the conclusion to that condition.
In this case the condition is if playerMoney.Value is greater or equal to the upgradeCost then we will tell the Buy Button to do something. Find out what the conclusion is on line 23-24.
In conclusion, if the players money is greater or equal to the upgradeCost then Roblox will print “Player can buy item” and give the player an upgrade (more spaces).
Playtest your project. Click the button and check that you can buy more spaces now after selling your items.