How would I make a team changer require a player to have a gamepass?

How would I make a team changer require a player to have a gamepass?

  1. I would like to make a team changer look for a gamepass within the script so if the person owns the gamepass they will change team, but if they don’t own the gamepass they won’t be able to change team.

  2. I have tried one way however it hasn’t worked! It is script 2 down below.

  3. I have looked for help on the HiddenDevs discord but I got no response. I have also looked on youtube but most are out-dated/don’t work.

Script 1
This is the normal script that I have works, however doesn’t offer the gamepass.

script.Parent.MouseButton1Click:Connect(function()
	game.ReplicatedStorage.ChangeTeamEvent:FireServer(script.Parent.Name)
end)

Script 2

script.Parent.MouseButton1Click:Connect(function()
    game.Players.PlayerAdded:Connect(function(plr)
        local ownsGamepass = game:GetService("MarketplaceService"):UserOwnsGamePassAsync(plr.UserId, 20542978)
        if ownsGamepass then
            game.ReplicatedStorage.ChangeTeamEvent:FireServer(script.Parent.Name)
        end
    end)
end)

This code is the one mentioned above, I have no clue on why it doesn’t work due to no output errors

1 Like

you need to create a remote event in the replicated storage

then put this in a local script in startergui

local GamepassID = 9427869
script.Parent.MouseButton1Click:Connect(function()
game.ReplicatedStorage. remote event name :FireServer()
end)

then create a script in workspace

and put

game.ReplicatedStorage.pass.OnServerEvent:Connect(function(plr)
local ownsGamepass = game:GetService("MarketplaceService"):UserOwnsGamePassAsync(plr.UserId, 20542978)
		if not ownsGamepass then
			-- change team code here 
		end
	end)

i think "MarketplaceService" can only be used on the server so it can’t be accessed locally

--LOCAL SCRIPT
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Marketplace = game:GetService("MarketplaceService")
local Replicated = game:GetService("ReplicatedStorage")
local ChangeTeam = Replicated:WaitForChild("ChangeTeamEvent")
local Button = script.Parent

Button.MouseButton1Click:Connect(function()
	local HasGamepass = Marketplace:UserOwnsGamePassAsync(Player.UserId, 20542978)
	if HasGamepass then
		ChangeTeam:FireServer(Button.Name)
	end
end)
--SERVER SCRIPT
local Teams = game:GetService("Teams")
local Replicated = game:GetService("ReplicatedStorage")
local ChangeTeam = Replicated:WaitForChild("ChangeTeamEvent")

ChangeTeam.OnServerEvent:Connect(function(Player, TeamName)
	local Team = Teams:FindFirstChild(TeamName)
	if Team then
		Player.Team = Team
	end
end)

The local script would go inside a TextButton or ImageButton of some ScreenGui instance. The server script would go inside the ServerScriptService. Make sure the name of the button matches the name of an existing team.

1 Like

If you figured this out can you please help. I I’m trying to do this for 9 hours.

but wouldn’t the UserOwnsGamePassAsync need the gamepass id? how would it get it if it is in the local script? Also why the “Not”? wouldn’t it indicate if the player doesn’t own the gamepass?

FYI, this approach is exploitable, which you should know ofc.

this service been exploitable forever lets be real