Greetings developers! Me and my friend are working on a project and he wants to have a gamepass team. I said okay and I made the team, made the team spawn, made the team select GUI and then the scripting part hit me. So I need help. My friend wants it so if the user clicks on the team and doesn’t have the gamepass, the user will get a prompt to purchase the gamepass. If the user DOES have the gamepass the prompt doesn’t show up and they automatically join the team. If you have any ideas or help please let me know. Thank you!
You would add a check to see if the player owns the gamepass or not.
local player = script.Parent.Parent.Parent.Parent.Parent
script.Parent.MouseButton1Click:Connect(function()
if --player owns gamepass (can't give you all the answers :) then
player.Team = game.Teams:FindFirstChild("[RRT] Rapid Response Team")
else
--prompt purchase
end)
You’re gonna need a few resources for this. First, you’ll want to use PromptGamePassPurchase from the MarketplaceService. Then, because UI is client-side, you’ll need to use a remote to send a request to join the team server-side. The server will then need to check if they own the gamepass with PlayerOwnsAsset. If they do, change their team. If not, prompt the purchase with the reference I gave earlier.
Firstly, you should just handle UI’s on the client, since that’s what they are meant to be handled on. You will need to use UserOwnsGamePassAsync to check if a player owns a game pass.
You will need to hook up a remote event so you can check on the server if they own the pass, then change their team accordingly.
Client Code
local Players = game:GetService("Players") -- Gets the service for players
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Player = Players.LocalPlayer
local Button = -- Define button from gui
local Remote = ReplicatedStorage:FindFirstChild("RemoteEvent")
Button.MouseButton1Click:Connect(function()
-- I would switch to Activated but it's preference
-- Fire remote to change their team
Remote:FireServer()
end)
Server Code
local Players = game:GetService("Players") -- Gets the service for players
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MarketplaceService = game:GetService("MarketplaceService")
local Remote = ReplicatedStorage:FindFirstChild("RemoteEvent")
local GamePassID = 0000 -- Edit to your needs
Remote.OnServerEvent:Connect(function(Player) -- First argument of server events are the player
local OwnsPass = MarketplaceService:UserOwnsGamePassAsync(Player.UserId,GamePassID)
-- Will return True or False, use this info for team changing
if OwnsPass then -- They own it
-- Change team
else
MarketplaceService:PromptGamePassPurchase(Player,GamePassID)
end
end)
PlayerOwnsAsset is used to check if a player owns an asset from the library or catalog. I don’t think it’s depreciated as there would be a tag on the wiki. PlayerOwnsGamePassAsync will check for Game passes only.