Im making a gear giving script; it gives a gear/item if the player owns a gamepass
heres the code:
Gamepasses = {
_6802285 = "MountainDew", -- R$66
_810384423 = "E" --
}
Exempt = {
-1, -- put ur username here to access all gamepasses w/o buying them
}
Tools = script:GetChildren()
game.Players.PlayerAdded:Connect(function(plr)
local Backpack = plr:WaitForChild("Backpack")
local StarterGear = plr:WaitForChild("StarterGear")
local IsExempt = false
for _,v in pairs(Exempt) do
if v == plr.UserId then
IsExempt = true
print("Exempt")
end
end
for _Id,ToolName in pairs(Gamepasses) do
local GID = string.sub(_Id,2)
if not IsExempt then
if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(plr.UserId,GID) then
for _,t in pairs(Tools) do
if ToolName == t.Name then
t:Clone().Parent = Backpack
t:Clone().Parent = StarterGear
end
end
end
else
for _,t in pairs(Tools) do
if ToolName == t.Name then
t:Clone().Parent = Backpack
t:Clone().Parent = StarterGear
end
end
end
end
end)
Gamepasses = {
["6802285"] = "MountainDew", -- R$66
["233444"] = "DragonBuddy", --
}
Exempt = {
-1, -- put ur username here to access all gamepasses w/o buying them
}
Tools = script:GetChildren()
game.Players.PlayerAdded:Connect(function(plr)
local Backpack = plr:WaitForChild("Backpack")
local StarterGear = plr:WaitForChild("StarterGear")
local IsExempt = false
for _,v in pairs(Exempt) do
if v == plr.UserId then
IsExempt = true
print("Exempt")
end
end
for Id,ToolName in pairs(Gamepasses) do
local GID = string.sub(Id,2)
if not IsExempt then
if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(plr.UserId,GID) then
for _,t in pairs(Tools) do
if ToolName == t.Name then
t:Clone().Parent = Backpack
t:Clone().Parent = StarterGear
end
end
end
else
for _,t in pairs(Tools) do
if ToolName == t.Name then
t:Clone().Parent = Backpack
t:Clone().Parent = StarterGear
end
end
end
end
end)
GID is a string, since you’re using string.sub on it. You have to call tonumber() on it before passing it into UserOwnsGamePassAsync. Also, you don’t need to use string.sub here since your IDs no longer have the underscore at the beginning, so you can just replace this bit with local GID = tonumber(Id)