#Backpack tool bug

1 messages · Page 1 of 1 (latest)

buoyant hull
#

how come when I join the game, only the speed coil or another random coil shows up in my inventory? only after I respawn do all the other tools show up. I want all tools (that the player bought) to show up when the player first joins the game

#

this is what shows when I join the game

native tapir
buoyant hull
native tapir
buoyant hull
native tapir
buoyant hull
#

ok

buoyant hull
#

nothing abt it shows in output

native tapir
#

weyt wut

#

oh that's the prompt finished

native tapir
#

put it in startergear only and don't :waitforchild every time. put it in a variable, set parent to it once.

#

in fact probably dont want the waitforchild at all

buoyant hull
native tapir
#

i thought that's what that chain was doing i didn't read it very closely..

buoyant hull
#

o lol

buoyant hull
native tapir
#

this is putting many scripts in one post and everyone gets confused..

buoyant hull
#

erm

#

maybe

native tapir
#

okay yeah that's the playeradded, parenting to startergear should go there

#

scroll in your output window

#

maybe its earlier

#

you do seem to have a lot of prints and stuff

buoyant hull
#

yea.. i have a lot

#

this is everything

native tapir
#

theoretically startergear should be created before their character

buoyant hull
#

alr

native tapir
buoyant hull
#

I see

icy kernelBOT
#

studio** You are now Level 22! **studio

buoyant hull
#

still doesn't work tho

native tapir
#

but ya setting to startergear should work if roblox docs are correct

buoyant hull
#

uhh

buoyant hull
native tapir
#

you wrapped the whole thing in pcall, which suppresses errors.

buoyant hull
#

oh

native tapir
#

though if it all appears in startergear then ids are correct and it is working, just at the wrong time

buoyant hull
#

yea they appear in startergear

#

just not backpack

native tapir
#

backpack gets destroyed and recreated on characteradded

#

oh right no, i know why

#

it's because getgamepass are async

#

so you need to add it to the character and the startergear the first time

#

2 clones

#

making sure to check if the player already has the tool first

buoyant hull
#

this is hella confusing for me ngl

native tapir
# buoyant hull this is hella confusing for me ngl

the thread called by playeradded yields until it gets a result from marketplaceservice, which can take up to about a second. and since you have them in series, it can take several seconds for all of them to return results. even if you put them in parallel with task.spawn each, you're still not guaranteed to have a result by the time the player gets their first character, so you have to check if the player already has the tool or not from startergear when you first receive gamepass result for each one.

#

startergear deals with it after the first time.

#

or i suppose you can just do if player.Character then -- clone to backpack on the first one, in addition to cloning to startergear thonkoof

buoyant hull
#

okk

native tapir
buoyant hull
#

lol all good

#

is it like this

#
            if player.Character then
            local speedCoil = gear.SpeedCoil:Clone()
            speedCoil.Parent = player.Backpack
            speedCoil.Parent = player:WaitForChild("StarterGear")
        end```
native tapir
buoyant hull
native tapir
# buoyant hull 😭

only because you're a mod and this is simple enough, consider it a perk of the job you do here

#

not many get this exception

#

@buoyant hull 🥣 ```lua
local function HasGamepassAsync(plr:Player,passId:number)
for i=1,5 do
local can,why = pcall(MarketplaceService.UserOwnsGamePassAsync, MarketplaceService, plr, passId)
if can then return why==true end
warn("Marketplace failed to check gamepass",passId,"for",plr,"because:",why)
task.wait(i*3)
if not plr.Parent then return false end
end
return false
end
local function CheckGamepass(plr:Player,passId:number,tool:Tool)
local hasPass=HasGamepassAsync(plr,passId)
if not HasGamepassAsync or not plr.Parent then return end
local plrGear=plr:WaitForChild("StarterGear")
if plr:FindFirstChild("Backpack") then
local clone=tool:Clone()
clone.Parent=player.Backpack
end
local clone=tool:Clone()
clone.Parent=plrGear
end

local Gamepasses = {
{id=000,toolname=""};
}::{{id:number;toolname:string}}

local ToolFolder = game:GetService("ServerStorage").Gear
local function PlayerAdded(plr:Player)
for _,gamepass in Gamepasses do
local toolTemplate=ToolFolder:FindFirstChild(gamepass.toolname)
if not toolTemplate then warn("Gamepass Tool not found",gamepass.toolname) continue end
task.spawn(CheckGamepass,plr,gamepass.id,toolTemplate)
end
end```

native tapir
#

typo hehe lua local function CheckGamepass(plr:Player,passId:number,tool:Tool) local hasPass=HasGamepassAsync(plr,passId) if not HasGamepassAsync or not plr.Parent then return end i wrote it in notepad, fixed the copypaste

#

the condition checks if not function, instead of if not hasPass woops

buoyant hull
#

but apart from that all is good TY

native tapir
buoyant hull
#

what i meant

#

being a mod sure is great

sullen island
icy kernelBOT
#

studio** You are now Level 3! **studio