Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to make a second variable?

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

0

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.

0

Currency.Value is an Instance then? I'm not seeing anything in here that would make it an Instance.

0

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

0

Remove both [] and put a waitforchild on currency

0

@ezkatka1 LocalPlayer is client-only. If you're doing this on the server, you will have to obtain a player in another way.

0

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

1 answer

Its easy to make another

script

local currency = player.leaderstats[player:WaitForChild("BackpackShop").Currency.Value
local currency2 = player.leaderstats[player:WaitForChild("BackpackShop2").Currency.Value] -- For example

1 comment

0

This probably does not fix his error.

This discussion is preserved as it was. New answers, comments, and votes are closed.