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 an item to the player who bought a gamepass?

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

✓ Accepted answer

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)

1 comment

0

To support Accept answer or thumbs it up

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)

1 comment

0

I say use the one I suggested I have tested it and it works fine

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