Id like to make a script that would allow people (that have a certain game-pass) to enter a game with no hassle. But kick any player that trys to join that doesn't have the game-pass. How would one start?
COMMUNITY QUESTION
How to make Server Lock Script (Gamepass)?
1 answer
You can check if the player owns a certain gamepass through the event UserOwnsGamepassAsync from MarketPlaceService.
With that being said you can just make a PlayerAdded event that gives the player, and check if the player owns the specified gamepass he should have, if not then Kick the player from the game.
Your script should look like this:
game:GetService("Players").PlayerAdded:Connect(function(Player)
local MarketPlaceService = game:GetService("MarketplaceService")
local GamepassID = ID -- Put your gamepass ID
if MarketPlaceService:UserOwnsGamePassAsync(Player.UserId, GamepassID) == false then -- If player does not own the gamepass
Player:Kick("Reason") -- Kick the player with the specified reason.
end
end)
Hopefully this solved your issue! Make sure to read more about MarketPlaceService as It'll definitely help you.
This discussion is preserved as it was. New answers, comments, and votes are closed.
