Hello there, I am in need of help to Make a Script which detects if someone owns a gamepass upon joining and then sets their Team accordingly.
So far I have looked far and wide for a souloution but have not found one.
(Basically, It checks for a gamepass with the ID of 52522 (For example) and then if the player has the gamepass they are assigned to a team called Alpha but if they dont have it they are assigned to a team called Beta.)
There is never always a solution you can easily find in programming. Programming is like a puzzle, it comes together from many different pieces and you just have to figure out what those pieces are.
To avoid spoonfeeding, I’m going to give you two pieces here:
local id = 7403435
local Players = game:GetService("Players")
local Teams = game:GetService("Teams")
local Team = Teams.Mechanoid
game.Players.PlayerAdded:Connect(function(player)
if game:GetService("GamePassService"):PlayerHasPass(player, id) then
player.Team = Team
else
print(player.Name .. " doesn't have the game pass...")
end
end)
However I’m getting this output : 03:10:24.939 - GamePassId ‘7403435’ is not of type Game Pass. Please use MarketplaceService:PlayerOwnsAsset instead.
GamePassService is deprecated. You are meant to use MarketplaceService.UserOwnsGamePassAsync. I thought @Qxest linked an actual article but it leads to a page that, at the very top, explicitly highlights in big bold and red: “Do not use for new work.”
local Players = game:GetService("Players")
local Teams = game:GetService("Teams")
local MarketplaceService = game:GetService("MarketplaceService")
local PASS_ID = 7403435
local function onPlayerAdded(player)
-- Canonically should be pcalled
if MarketplaceService:UserOwnsGamePassAsync(player, PASS_ID) then
player.Team = Teams.Mechanoid
end
end
Players.PlayerAdded:Connect(onPlayerAdded)
for _, player in ipairs(Players:GetPlayers()) do
onPlayerAdded(player)
end
Game passes have a separate id system from all other assets. GamePassService is meant to be used with game passes that also have an id from the legacy system, though the legacy id shouldn’t be used. UserOwnsGamePassAsync is built to function with the GamePassId system in mind.