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

I was wondering how I could make a button in game that teleport you to a different place?

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

0

This is not a request site, please at least attempt to make the code before asking us about issues.

0

I did I just forgot to add it - this is my first time using the website, sorry!

1 answer

I would suggest looking at this article: https://developer.roblox.com/en-us/articles/Teleporting-Between-Places

local PlaceID = 1234567

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
		TeleportService:Teleport(PlaceID, player) --Teleport!!
	end
end

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