Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
Slatryte 104
4 years ago
Edited 4 years ago

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?

0
My apologies, I made syntax error Ziffixture 6913 — 4y

2 answers

Log in to vote
0
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

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
0
It doesn't work, it gives this message: "Arguement 1 nil or missing." Slatryte 104 — 4y
0
It’s fixed Ziffixture 6913 — 4y
0
Alright. Slatryte 104 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

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()
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. Slatryte 104 — 4y
0
This only applies to :TeleportToPrivateServer(). Ziffixture 6913 — 4y

Answer this question