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

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

Asked by 5 years ago

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

0
Your lua brackets are messed up. DinozCreates 1070 — 5y
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 User#22604 1 — 5y
1
you can set player.Team to make a player be on a specific team https://developer.roblox.com/api-reference/property/Player/Team User#22604 1 — 5y
0
i copy pasted that off the website not my script sillyjake285 0 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

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!

Ad

Answer this question