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)
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)
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.
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