I'm currently making a 'Theme Park' game, and I've run into a bit of trouble with a tool game-pass script. I've tried multiple attempts and can't get it to work. Any help is widely appreciated. Heres my script:
local Lighting = game:GetService("Lighting") local MarketplaceService = game:GetService("MarketplaceService") local Players = game:GetService("Players") local gamepassId = 5053560 --Put that id here local toolNames = {"InfinityRides"} local toolsParent = Lighting local function onPlayerAdded(player) local function onCharacterAdded(character) if MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamepassId) then for i = 1, #toolNames do local tool = toolsParent:FindFirstChild(toolNames[i]) if tool then local clone = tool:Clone() clone.Parent = player.Backpack end end end end if player.Character then onCharacterAdded(player.Character) end player.CharacterAdded:Connect(onCharacterAdded) end
The issue is what you are doing at the bottom of the code you never call the function in the first place. You are trying to call the function. I just rewrote your entire code because I'm bored. Either use it or just look at what I did and try to see what is wrong. For the future I also recommend you to use print to found out what the error is.
local ServerStorage = game:GetService("ServerStorage") local MarketplaceService = game:GetService("MarketplaceService") local Players = game:GetService("Players") local GamepassId = 5053560 --Put that id here local ToolNames = {"InfinityRides"} local ToolsParent = ServerStorage game.Players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(character) print("Checking if ".. player.Name.. " owns the gamepass with the id of ".. GamepassId) if MarketplaceService:UserOwnsGamePassAsync(player.UserId, GamepassId) then print("The player ".. player.Name.. " owns the gamepass with the id of ".. GamepassId) for i, v in pairs(ToolNames) do print("Looking for the tools to give the player ".. player.Name) if ServerStorage:FindFirstChild(v) then print("Found tool to give the player ".. player.Name) local ClonedTool = ServerStorage:FindFirstChild(v):Clone() ClonedTool.Parent = player.Backpack end end end end) end)