So I was given a working script to help me with adding gears into a game when they owned a gamepass, simple right?
Oddly, even after adding the id of the gamepass and the name of the gear (and add it in the storage server as required), it doesn’t load in at all.
here is the script:
local Id = 15048165
local ToolName = {“RainbowMagicCarpet”}
for _, Player in pairs(game.Players:GetChildren()) do
if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(Player.UserId, Id) then
Player.CharacterAdded:Connect(function(character)
for Num, Tool in pairs(ToolName) do
if game:GetService("ServerStorage"):FindFirstChild(Tool) then
if Player.Backpack:FindFirstChild(Tool) then
else
game:GetService("ServerStorage")[Tool]:Clone().Parent = Player.Backpack
end
end
end
end)
for Num, Tool in pairs(ToolName) do
if Player.Backpack:FindFirstChild(Tool) == nil then
if game:GetService("ServerStorage"):FindFirstChild(Tool) then
if Player.Backpack:FindFirstChild(Tool) then
else
game:GetService("ServerStorage")[Tool]:Clone().Parent = Player.Backpack
end
end
end
end
end
end
game.Players.PlayerAdded:Connect(function(Player)
if game:GetService(“MarketplaceService”):UserOwnsGamePassAsync(Player.UserId, Id) then
Player.CharacterAdded:Connect(function(character)
for Num, Tool in pairs(ToolName) do
if game:GetService(“ServerStorage”):FindFirstChild(Tool) then
if Player.Backpack:FindFirstChild(Tool) then
else
game:GetService(“ServerStorage”)[Tool]:Clone().Parent = Player.Backpack
end
end
end
end)
for Num, Tool in pairs(ToolName) do
if Player.Backpack:FindFirstChild(Tool) == nil then
if game:GetService("ServerStorage"):FindFirstChild(Tool) then
if Player.Backpack:FindFirstChild(Tool) then
else
game:GetService("ServerStorage")[Tool]:Clone().Parent = Player.Backpack
end
end
end
end
end
end)
Am I missing something in this script in order to work?
I checked everywhere and they always say to add the id of the gamepass and name of the gear (I was hoping for adding the id of the gear, but oh well.)
Hello! Seeing this script it makes me feel It’s overcomplicating for the solution.
I see you want to make it so if the player has the gamepass it gives the tool. This can be done by simply inserting the tools in ServerStorage and with a PlayerAdded connection check if the tool is in ServerStorage and clone it to the player’s backpack and startergear.
local MarketService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local Id = 15048165
local ToolNames = {"Tool1", "Tool2"}
Players.PlayerAdded:Connect(function(player)
if MarketService:UserOwnsGamePassAsync(player.UserId , Id) then
for i,Name in pairs (ToolNames) do
local Tool = game.ServerStorage[Name]
if Tool then
Tool:Clone().Parent = player.Backpack
Tool:Clone().Parent = player.StarterGear
end
end
end
end)
This checks for every name in ToolNames to see if they exist in ServerStorage, if so then it’ll clone to the player’s Backpack and StarterGear
Make sure your gear is in ServerStorage, you can put a WaitForChild() in local Tool if you want.
However this script works completly fine for me, it gives me both tools when I enter the game and when I die.
Of course it won’t work if you buy the gamepass while in-game, since It’s connected to PlayerAdded, to fix that you can make this script a function:
function GiveTool(player)
if MarketService:UserOwnsGamePassAsync(player.UserId , Id) then
for i,Name in pairs (ToolNames) do
local Tool = game.ServerStorage[Name]
if Tool then
Tool:Clone().Parent = player.Backpack
Tool:Clone().Parent = player.StarterGear
end
end
end
end
Hey you can use my script which I use its simple and easy to use:
local MarketPlaceService = game:GetService("MarketplaceService")
local GamepassID = 5059047 -- Put the gamepads id here
local tool = game.ServerStorage.[Insert Tool] --Put tool name here
game.Players.PlayerAdded:Connect(function(player)
if MarketPlaceService:UserOwnsGamePassAsync(player.UserId, GamepassID) then --if player has gamepass then
tool:Clone().Parent = player:WaitForChild("Backpack")
tool:Clone().Parent = player:WaitForChild("StarterGear")
--Moves tool into players Backpack
end
end)