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

How do I give an item to the player who bought a gamepass?

Asked by 10 years ago

I'm making a script for my gamepass, but i'm stuck now! I don't know how to clone something into a players backpack and make it stay there permanently.

What i've got so far

local passId = 198893078 -- change this to your game pass ID.

function isAuthenticated(player) -- checks to see if the player owns your pass
    return game:GetService("GamePassService"):PlayerHasPass(player, passId)
end

game.Players.PlayerAdded:connect(function(plr)
    if isAuthenticated(plr) then
        print(plr.Name .. " has bought the game pass with id " .. passId)
    end
end)

2 answers

Log in to vote
2
Answered by 10 years ago

Here you can use this script:

local GamePassID = 197848488  --game pass ID
local Tools = {'ShieldSphere'}    --Put the tools names here. (Tools must be held in the lighting of your game)

local gps = Game:GetService("GamePassService")

function playerJoined(newPlayer)
    if gps:PlayerHasPass(newPlayer,GamePassID) then
        for i,v in ipairs (Game.Lighting:GetChildren()) do
            for a,c in pairs (Tools) do
                if v.Name:lower()==c:lower() and v:IsA'Tool' then
                    repeat wait() until newPlayer:FindFirstChild("Backpack") and newPlayer:FindFirstChild("StarterGear")
                    v:Clone().Parent = newPlayer.StarterGear
                    v:Clone().Parent = newPlayer.Backpack
                end
            end
        end
    end
end

Game.Players.PlayerAdded:connect(playerJoined)
0
To support Accept answer or thumbs it up TixyScripter 115 — 10y
Ad
Log in to vote
0
Answered by 10 years ago

Or will this work?

local passId = 198893078 -- change this to your game pass ID.

function isAuthenticated(player) -- checks to see if the player owns your pass
    return game:GetService("GamePassService"):PlayerHasPass(player, passId)
end

game.Players.PlayerAdded:connect(function(plr)
    if isAuthenticated(plr) then
    local sord = game.ReplicatedStorage.ITEMS.GamepassSword
        print(plr.Name .. " has bought the game pass with id " .. passId)
        sord:Clone(plr.Backpack)
    end
end)
0
I say use the one I suggested I have tested it and it works fine TixyScripter 115 — 10y

Answer this question