I'm new to scripting, and I've been working on a game recently called "S.S Hortonia" and I want to know how I can put someone on a team if they have a certain gamepass. I already have a gamepass called "Donate" and I have a script to detect if a player had that gamepass when they joined, but I wanted to know how to put them on a team if they had it. Here's the script I used, off the roblox developer page:
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local gamePassID = 0000000 -- Change this to your game pass ID
local function onPlayerAdded(player)
local hasPass = false
local success, message = pcall(function()
hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID)
end)
if not success then
warn("Error while checking if player has pass: " .. tostring(message))
return
end
if hasPass == true then
print(player.Name .. " owns the game pass with ID " .. gamePassID)
end
end
Players.PlayerAdded:Connect(onPlayerAdded)
Link to game if useful: https://www.roblox.com/games/2562800778/S-S-Hortonia

4 comments
Your lua brackets are messed up.
did you change the gamepass ID like it says to? if you're just going to copy paste and not actually look at the script, you're not going to get very far
you can set player.Team to make a player be on a specific team https://developer.roblox.com/api-reference/property/Player/Team
i copy pasted that off the website not my script