Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I give the player specific privileges but only when he as a gamepass?

For example I want a part to go transparent but only for the player with the gamepass?

Suppose the gamepass is: "www.roblox.com/xyz"

According to the given example, please provide a script for reference and example.

In the same process, explain how I can make and use a client-sided script here.

2 answers

✓ Accepted answer
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
 
local gamePassID = 0000000  -- Change this to your game pass ID
 
local function onPlayerAdded(player)
 
    local hasPass = false
 
    -- Check if the player already owns the game pass
    local success, message = pcall(function()
        hasPass = MarketplaceService:UserOwnsGamePassAsync(player.userId, gamePassID)
    end)
 
    -- If there's an error, issue a warning and exit the function
    if not success then
        warn("Error while checking if player has pass: " .. tostring(message))
        return
    end
 
    if hasPass == true then
        --When Client as Pass
    end
end
 
-- Connect 'PlayerAdded' events to the 'onPlayerAdded()' function
Players.PlayerAdded:Connect(onPlayerAdded)

ROBLOX Code, but I commented the important part.

2 comments

0

what does the pcall and tostring do?

0

The pcall will un the function in protected call mode, meaning you can ignore or handle errors during the call. I don't believe it's necessary for this, though. As for the tostring(), that would be unnecessary. If the function pcall calls errors, it would return the error message as the second return value.

This discussion is preserved as it was. New answers, comments, and votes are closed.