Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago

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

Log in to vote
0
Answered by 5 years ago

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)
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** casper123123123 357 — 5y
0
Yes I did. Now it only shows "Checking" IPhoneDrew 9 — 5y
0
Please give a link to your gamepass. casper123123123 357 — 5y
View all comments (2 more)
0
Do you have discord. So I can answer quicker. casper123123123 357 — 5y
0
Yes. enigma drew#9974 IPhoneDrew 9 — 5y
Ad

Answer this question