In my map you run around and collect stars which you can then trade in for the in game currency. I have made a button in the game which I want to teleport you to the next level (a different place) but only if you have enough in game currency. Could someone please help me with this?
The following script is what I used previously with the same type of button but for buying extra space in the game (toilet roll is currency and obviously spaces are spaces):
-- Lets players click a button to buy an upgrade that increases MaxSpaces local BuyButton2 = script.Parent local ClickDetector = BuyButton2.ClickDetector
-- Variables for the upgrade local newSpaces = 30 local upgradeCost = 1000
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("Toilet Roll") 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
end
end

2 comments
This is not a request site, please at least attempt to make the code before asking us about issues.
I did I just forgot to add it - this is my first time using the website, sorry!