Gamepass whitelist

How would I add a game pass whitelist along with the user whitelist already in this script?

serverlock = true

local Whitelisted = {"KaylaPls"}
local Remote = game.ReplicatedStorage.SlockUnslock

Remote.OnServerEvent:Connect(function(Player,LockVal)
	wait()
	print(LockVal)
	if LockVal == "Locked" then
		serverlock = true
	end

	if LockVal == "Unlocked" then
		serverlock = false
	end

end)
game.Players.PlayerAdded:Connect(function(Player)
	if serverlock and table.find(Whitelisted, Player.Name) == nil then
		Player:Kick("This event hasn't started yet!")
	end
end)
3 Likes

You can make a variable for the gamepassID then use the or operator and check if they own the gamepass using UserOwnsGamePassAsync after you check if they are inside of the whitelist table.

2 Likes

Do you mind typing out what that might look like?

hm you mean, whitelisted people who can enter?
if so then

serverlock = true

local Whitelisted = {"KaylaPls"}
local Remote = game.ReplicatedStorage.SlockUnslock

Remote.OnServerEvent:Connect(function(Player,LockVal)
	wait()
	print(LockVal)
	if LockVal == "Locked" then
		serverlock = true
	end

	if LockVal == "Unlocked" then
		serverlock = false
	end

end)
game.Players.PlayerAdded:Connect(function(Player)
	if serverlock and table.find(Whitelisted, Player.Name) == nil then
		Player:Kick("This event hasn't started yet!")
elseif serverlock and table.find(Whitelisted, Player.Name) then
		--make a script for the whitelisted people
	end
2 Likes

if you wanna do a gamepass for it then

local gamepassid = "gamepassidhere"
local serverlock = true

local Whitelisted = {"KaylaPls"}
local Remote = game.ReplicatedStorage.SlockUnslock

Remote.OnServerEvent:Connect(function(Player, LockVal)
	wait()
	print(LockVal)
	if LockVal == "Locked" then
		serverlock = true
	end

	if LockVal == "Unlocked" then
		serverlock = false
	end

end)
game.Players.PlayerAdded:Connect(function(Player)
	if serverlock and table.find(Whitelisted, Player.Name) == nil then
		Player:Kick("This event hasn't started yet!")
elseif game:GetService("MarketplaceService"):UserOwnsGamePassAsync(Player.UserId,  gamepassid) then
		table.insert(Whitelisted, Player.Name)
	end

It inserts the name in the table of who owns the gamepass.

2 Likes

make sure to change the gamepassid value to your gamepass id

1 Like

Your elseif is making it so if the server is not locked then add their name to the whitelist table, plus this method of adding players to the table won’t count if they delete the gamepass after they join the server.

1 Like

I made a mistake, I edited it though. You may try the script.

1 Like

Well, then she can change it to if + I gave her a tip by saying table.insert()

1 Like

There are alot of ways to do what she’s trying to do.

1 Like

This is what it should look like, and I fixed up the method of checking if they are in the table.

EDITED: Check now @KaylaPls

local MarketplaceService = game:GetService("MarketplaceService")

local Whitelisted = {"KaylaPls"}
local GamepassID = 2653349 -- Random numbers, replace
local Remote = game.ReplicatedStorage.SlockUnslock

serverlock = true

Remote.OnServerEvent:Connect(function(Player,LockVal)
	wait()
	print(LockVal)
	if LockVal == "Locked" then
		serverlock = true
	end

	if LockVal == "Unlocked" then
		serverlock = false
	end
end)

game.Players.PlayerAdded:Connect(function(Player)
	if serverlock then
		if not table.find(Whitelisted, Player.Name) or not MarketplaceService:UserOwnsGamePassAsync(Player.UserId,GamepassID) then
			Player:Kick("This event hasn't started yet!")
		end
	end
end)
3 Likes

I tried your method with a gamepass I owned and without me being in the user whitelist, it still kicked me

I think this is what you asked for.

 local GamePassId = 0 --add your gamepass id here it can be found in the gamepasse's url    
    local serverlock = true -- I made this local there's no real point in it being global

        local Whitelisted = {"KaylaPls"}
        local Remote = game.ReplicatedStorage.SlockUnslock

        Remote.OnServerEvent:Connect(function(Player,LockVal)
        	wait()
        	print(LockVal)
        	if LockVal == "Locked" then
        		serverlock = true
        	end

        	if LockVal == "Unlocked" then
        		serverlock = false
        	end

        end)
        game.Players.PlayerAdded:Connect(function(Player)
        	if serverlock and (not Whitelisted[Player.Name] or not game:GetService("MarketplaceService"):UserOwnsGamePassAsync(Player.UserId,GamePassId)) then
     --if the player isn't whitelisted or doesn't own the specified gamepass it kicks them
        		Player:Kick("This event hasn't started yet!")
        	end
        end)

Yea, I tried it again, it still kicked me (I took my name out of whitelist and tried it with a gamepass I owned. I also tried it without me owning a gamepass and just my name in the whitelist, that didn’t work as well).

local Whitelisted = {["KaylaPls"] = true} 

local Gamepass = 123456
local serverlock = {}

local Remote = game.ReplicatedStorage.SlockUnslock

Remote.OnServerEvent:Connect(function(Player,LockVal)
	wait()
	print(LockVal)
	if LockVal == "Locked" then
		serverlock["Server"] = true
	end
	if LockVal == "Unlocked" then
		serverlock["Server"] = false
	end
end)

game.Players.PlayerAdded:Connect(function(Player)
	if serverlock["Server"] then
		if (not Whitelisted[Player.Name]) then
			Player:Kick("Not whitelisted")
		end
		if not (game:GetService("MarketplaceService"):UserOwnsGamePassAsync(Player.UserId, Gamepass)) then
			Player:Kick("Not got gamepass.")
		end
	end
end)

Have a try of this

1 Like

Yes, they forgot to make the whitelist table a dictionary. This should fix it.

Edit: OOPS NVM there are definitely some issues still.

Edit 2: Lol they fixed it just as I saved that edit.

1 Like

If you’re meaning mines, yeah, It’s 3 am lol I’m tired as heck

1 Like

Actually, there are still issues so i’ll help you out.

game.Players.PlayerAdded:Connect(function(Player)
	if serverlock["Server"] then
		if (not Whitelisted[Player.Name]) and (not game:GetService("MarketplaceService"):UserOwnsGamePassAsync(Player.UserId, Gamepass)) then
			Player:Kick("This server is currently locked!")
		end
	end
end)
1 Like

Just realised, I only read the top part, I’d thought she wanted an additional whitelist on top of the name, not that she wanted it so if you had the gamepass it still let you through haha - (my view, if the player is in the whitelist, let him in, but if he doesn’t own the gamepass kick)

1 Like