Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 6 years ago

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

Log in to vote
0
Answered by
TheePBHST 154
6 years ago
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.

0
what does the pcall and tostring do? AlexStorms 21 — 6y
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. Avigant 2374 — 6y
Ad
Log in to vote
0
Answered by
Avigant 2374 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago

We can use this method: http://wiki.roblox.com/index.php?title=API:Class/MarketplaceService/UserOwnsGamePassAsync

This code would be client-side:

local MarketplaceService = game:GetService("MarketplaceService")

local LocalPlayer = game.Players.LocalPlayer

local VipGamepassId = 293922
local VipDoor = game.Workspace.VipDoor

if MarketplaceService:UserOwnsGamePassAsync(LocalPlayer.UserId, VipGamepassId) then
    VipDoor.Transparency = 1
end

Answer this question