local currency = player.leaderstats[player:WaitForChild("BackpackShop").Currency.Value]
So i want to somehow separate this into 2 variables because sometimes Currency is not loaded because there is no WaitForChild for it and it gives an error. I've tried these but this gives me an error:
local currenc = player.leaderstats[player:WaitForChild("BackpackShop")] local currency = currenc:WaitForChild("Currency").Value this gives this error: Players.ezkatka1.PlayerGui.BackpackShop.Frame.Buy.buy:4: invalid argument #2 (string expected, got Instance)
and this: local currenc = player.leaderstats.player:WaitForChild("BackpackShop") local currency = currenc:WaitForChild("Currency").Value this one gives this error: player is not a valid member of Folder "Players.ezkatka1.leaderstats"
Any Ideas?

6 comments
This is because the player does not exist yet, try putting a waitforchild on both the player and currency. Reply if it does still not work.
Currency.Value is an Instance then? I'm not seeing anything in here that would make it an Instance.
Yea that works. I got Infinite yield possible on 'Players:WaitForChild("LocalPlayer") but i assume its not gonna be a problem right? Since the script wont be running if there is no Players in A server(it will auto close the roblox game sever) if im not wrong
Remove both [] and put a waitforchild on currency
@ezkatka1 LocalPlayer is client-only. If you're doing this on the server, you will have to obtain a player in another way.
I did local player = game:GetService("Players") local player2 = player:WaitForChild("LocalPlayer") and this gives the infinite yield but my selection menu for backpacks is broken so this way it wont work. Any ideas? Btw its a localscript