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

making a tool only accessible to players who bought the gamepass?

Asked by 4 years ago

so this is the code

local MarketPlaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
game.Players.PlayerAdded:Connect(function(plr)
    local success, message = pcall(function()
        local haspass = false
        local gamepassID = 9794050
        haspass = MarketPlaceService:UserOwnsGamePassAsync(plr.UserId, gamepassID)
        if haspass == true then
            local gravitycoil = plr.Backpack.GravityCoil 
            gravitycoil.Enabled = true
        end
    end)
end)

so there is a tool in starter pack and it is a gravity coil this code makes it so the coil is enabled if they bought the gamepass the gravitycoil.enable = true runs so idk if enabled works i read that it makes it unusable if it is false and i have it automatically set to false so could you tell me if im doing something wrong or a different way to do it like .activation or something like that?

0
check studioplus.io Lightning_Game27 232 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

Hope this helps, there are many ways on making gamepass scripts but, i just find this more suitable and does work.

local id = 0  --gamepass id
local t2 = game.ServerStorage.toolName
game:GetService("MarketplaceService").PromptGamePassPurchaseFinished:Connect(function(plr,ido,purchased)
    if purchased and ido == id then
    plr.CharacterAdded:connect(function(char) 
     t2.Parent = plr.StarterGear
     t2:Clone().Parent = plr.Backpack  
end)
    end
end)

game.Players.PlayerAdded:Connect(function(plr)   
    plr.CharacterAdded:connect(function(char)
 if  game:GetService("MarketplaceService"):UserOwnsGamePassAsync(game.Players[char.Name].UserId, id) then
         t2.Parent = plr.StarterGear
     t2:Clone().Parent = plr.Backpack  
        end
    end)
end)

also make sure that if above game is next to game.

Ad

Answer this question