Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to fix a game pass tool script after multiple attempts?

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

1 answer

✓ Accepted answer

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)

6 comments

0

Did you see that I moved the tool into ServerStorage instead? No particular reason I just don't like having it inside of Lightning

0

Yes I did. Now it only shows "Checking"

0

Please give a link to your gamepass.

0

Do you have discord. So I can answer quicker.

0

Yes. enigma drew#9974

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