Gamepass whitelist

I have a Night vision goggles giver but its a game pass on my game. so only people with the gamepass can use it. but is it possible to add a whitelist so if the player is on the list they don’t need to buy it and can just use it? here is my script:

local uis = game:GetService("UserInputService")
local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")
local Lighting = game:GetService("Lighting")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local char = script.Parent

local equipRE = ReplicatedStorage:WaitForChild("NVGsToggled")

local defaultAmbient = Lighting.OutdoorAmbient

local GamepassID = 17829472

local player = Players.LocalPlayer

if MarketplaceService:UserOwnsGamePassAsync(player.UserId, GamepassID) then
	print("Owns gamepass")
	uis.InputBegan:Connect(function(input, processed)
		if processed then return end

		if input.KeyCode == Enum.KeyCode.K then
			if not char:FindFirstChild("NVGs") then
				equipRE:FireServer(true)
				game.Workspace.Sounds["Night Vision Goggles Sound Effect"]:Play()

				Lighting.OutdoorAmbient = Color3.fromRGB(255, 255, 255)
				Lighting.NVG.Enabled = true
			else
				equipRE:FireServer(false)
				Lighting.OutdoorAmbient = defaultAmbient
				Lighting.NVG.Enabled = false
			end
		end
	end)
end
1 Like

I suggest trying to put: or player.UserId == "FriendsUserIdHere" right in the 17th line before the then.

Nope. I tried but it does not work.

try this

local uis = game:GetService("UserInputService")
local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")
local Lighting = game:GetService("Lighting")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local WhitelistedPlayers = {"FriendNameHere","OtherFriendNameHere"}--You Can Have As Many Names Here As You Want, Just Make Sure To Add Another Comma And Another Set Of Quotes.

local char = script.Parent

local equipRE = ReplicatedStorage:WaitForChild("NVGsToggled")

local defaultAmbient = Lighting.OutdoorAmbient

local GamepassID = 17829472

local player = Players.LocalPlayer

if MarketplaceService:UserOwnsGamePassAsync(player.UserId, GamepassID) or table.find(WhitelistedPlayers,player.Name) then
	print("Owns gamepass")
	uis.InputBegan:Connect(function(input, processed)
		if processed then return end

		if input.KeyCode == Enum.KeyCode.K then
			if not char:FindFirstChild("NVGs") then
				equipRE:FireServer(true)
				game.Workspace.Sounds["Night Vision Goggles Sound Effect"]:Play()

				Lighting.OutdoorAmbient = Color3.fromRGB(255, 255, 255)
				Lighting.NVG.Enabled = true
			else
				equipRE:FireServer(false)
				Lighting.OutdoorAmbient = defaultAmbient
				Lighting.NVG.Enabled = false
			end
		end
	end)
end
1 Like