Unable to cast string to bool

I have a gamepass gui in my game and I’ve been getting this error every time the game loads up and have been stuck tryna figure it out.

local gamepassIDs = {
[51128872] = game.ReplicatedStorage.GamepassItems:FindFirstChild("GravityCoil","SpeedCoil"),  --The error happens on this line.
[24648574] = game.ReplicatedStorage.GamepassItems:FindFirstChild("2x Points"),
[44749199] = game.ReplicatedStorage.GamepassItems:FindFirstChild("SubspaceTripmine"),
[51096216] = game.ReplicatedStorage.GamepassItems:FindFirstChild("MultiRocket")	,
}

local mps = game:GetService("MarketplaceService")


game.Players.PlayerAdded:Connect(function(c)
for id, tool in pairs(gamepassIDs) do
	if mps:UserOwnsGamePassAsync(c.UserId, id) then
		
		tool:Clone().Parent = c.Backpack
	    tool:Clone().Parent = c.StarterGear
	end
end
end)


mps.PromptGamePassPurchaseFinished:Connect(function(c, id, purchased)

if purchased and gamepassIDs[id] then
	
	gamepassIDs[id]:Clone().Parent = c.Backpack		
	gamepassIDs[id]:Clone().Parent = c.StarterGear
	
    end
end)
1 Like

The second argument should not be a string.
The second argument is the seconds the function max waits for the instance.

1 Like

The second parameter determines whether the search is recursive
You should read the documentation on :FindFirstChild()

Replace that line with this:

[51128872] = game.ReplicatedStorage.GamepassItems:FindFirstChild("GravityCoil"), 
[51128872] = game.ReplicatedStorage.GamepassItems:FindFirstChild("SpeedCoil"), 
2 Likes

Wouldn’t it override the first values?

It would. A way to do it would probably be to store everything you want to give under that gamepass id in a table, then loop through the table, and give all the items one by one. @Gwyllgi

local gamepassIDs = {
    [51128872] = { game.ReplicatedStorage.GamepassItems:FindFirstChild("GravityCoil"), game.ReplicatedStorage.GamepassItems:FindFirstChild("SpeedCoil") },
    [24648574] = game.ReplicatedStorage.GamepassItems:FindFirstChild("2x Points"),
    [44749199] = game.ReplicatedStorage.GamepassItems:FindFirstChild("SubspaceTripmine"),
    [51096216] = game.ReplicatedStorage.GamepassItems:FindFirstChild("MultiRocket")	,
}

game.Players.PlayerAdded:Connect(function(c)
    for id, tool in pairs(gamepassIDs) do
	    if mps:UserOwnsGamePassAsync(c.UserId, id) then
            if type(tool) == "table" then
                for _,v in pairs(tool) do
                    v:Clone().Parent = c.Backpack
                    v:Clone().Parent = c.StarterGear
                end
            else
                tool:Clone().Parent = c.Backpack
                tool:Clone().Parent = c.StarterGear
            end
	    end
    end
end)

mps.PromptGamePassPurchaseFinished:Connect(function(c, id, purchased)

    if purchased and gamepassIDs[id] then
	
	    if type(gamepassIDs[id]) == "table" then
            for _,v in pairs(gamepassIDs[id]) do
                v:Clone().Parent = c.Backpack
                v:Clone().Parent = c.StarterGear
            end
        else
            gamepassIDs[id]:Clone().Parent = c.Backpack		
	        gamepassIDs[id]:Clone().Parent = c.StarterGear
        end
	
    end
end)
1 Like

At which line error accured to be exact?
Edit:
I just read your comments nvm
Bro just read documentation bruh

It accepts boolean but you pass a string parameter :skull::skull::skull:

…just why.

[51128872] = game.ReplicatedStorage.GamepassItems.GravityCoil.SpeedCoil

He doesnt even use FindFirstChild properly so what the point even to have it?

What you just said has nothing to do with shared’s response, not that his was correct but yours isn’t even relatively close to what he said. Assuming he’s using roblox’s famous speed and gravity coils, they are 2 different items, and he probably wants to give both, you are accessing one instance under gravitycoil named SpeedCoil, which just doesn’t make sense.

It does tho.
I solved issues your code had and solved his issues too; Any questions?

The post wasn’t made by me, my reply to the actual author works perfectly fine, and there was nothing to fix on shared’s response as it’s not an actual valid fix to anything, his explanation is correct tho. It’s only his “fix” that is messed up. edit: i won’t be replying further, my initial reply to the author works perfectly fine, so i wont argue further

Thank you.! Changing the one line you changed fixed it.

1 Like