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

How do I make my gamepass put someone on a team?

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

0

Your lua brackets are messed up.

0

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

1

you can set player.Team to make a player be on a specific team https://developer.roblox.com/api-reference/property/Player/Team

0

i copy pasted that off the website not my script

1 answer

So, first of all, making such a long script is pretty unnecessary.

Put this in a Local Script

local passId = 0000 --Put your gamepass ID here
local plr = game:GetService("Players") --Gets player list

player.CharacterAdded:Connect(onCharacterAdded) -- Initiates script when a new player is added
if game:GetService("MarketplaceService"):PlayerOwnsAsset(plr, passId) then --Checks if you own the gamepass
		print(plr.Name .. " Owns this gamepass") --Prints Owns
                plr.Team = game.Teams.TeamName --Changes the players team
	else
		print(plr.Name .. " Doesn't own this gamepass") --Prints Doesn't own
	end

IMPORTANT

Make sure to change "TeamName" to the name of the team you want the player to be on plr.Team = game.Teams.TeamName (Line 7) Make sure to change "0000" to the gamepass ID local passId = 0000 (Line 1)

If this doesn't work please tell me in the comments.

If this answer was good please upvote it and mark it as correct.

Good luck with your game!

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