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

(ANSWERED) How do I get this game-teleporting button to work?

#Introduction So I am trying to get this button to teleport the player to another game if they have ownership to the game, but if not, they will be prompted to purchase it. But it doesn't really seem to work; when I click the button, it does absolutely nothing.

Here is my script:

function hi(player)
	GameID = 199362426
	game.Players.PlayerAdded:connect(function(player)
	game:GetService("TeleportService"):Teleport(GameID, player)
end)
	local market=game:GetService("MarketplaceService")
	market:PromptPurchase(player,2016087191)
end
script.Parent.TextButton.MouseButton1Click:Connect(function()

#Conclusion Can somebody help me?

1 comment

0

My apologies, I made syntax error

2 answers

✓ Accepted answer

If you wish to verify that a given user owns an Asset, you can use MarketplaceService’s :PlayerOwnsAsset() method. This function returns a Boolean result, allowing us to build a conditional statement with this function to only run blocks of code if the ownership proves True. The function can also verify Paid Access places, so altogether, we can apply this in your Script.

local MarketplaceService = game:GetService("MarketplaceService")
local PaidAccessAssetId = --// PlaceId of Paid Access Game.

local Player = game:GetService("Players").LocalPlayer

if (MarketplaceService:PlayerOwnsAsset(Player, PaidAccessAssetId) then
    --// Teleport
else
    MarketplaceService:PromptPurchase(Player, PaidAccessAssetId)
end

3 comments

0

It doesn't work, it gives this message: "Arguement 1 nil or missing."

0

It’s fixed

0

Alright.

For the Teleport to work, you need to use an array of players. So you can just do {} on the player object to turn it into an array so Roblox can tp it.

function hi(player)
    GameID = 199362426
    game.Players.PlayerAdded:connect(function(player)
    game:GetService("TeleportService"):Teleport(GameID, {player})
end)
    local market=game:GetService("MarketplaceService")
    market:PromptPurchase(player,2016087191)
end
script.Parent.TextButton.MouseButton1Click:Connect(function()

2 comments

0

I mean the teleport works, but I need to make it so if they don't own the game, it prompts them the purchase, and if they do own the game, it teleports them.

0

This only applies to :TeleportToPrivateServer().

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