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)
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.
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
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
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.
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)
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)
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)
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)