Unable to cast to array

I’m writing a datastore and I keep getting the error in the title

Code: The error is on line 36

It’s because you need to put it in a table I’m pretty sure. Try this:

local SaveValues = {
WinValue = Leaderstats.Wins.Value,
MoneyValue = Leaderstats.Money.Value,
}

I may be wrong though, so my second solution is to change the spelling. You see the “Leaderstats” you wrote below line 33 is a capital L whereas the actual leaderstats name is “leaderstats” so maybe just instead write Player.leaderstats.Wins.Value you know?

Yea your right I’m looking at the documentation and if its more then 1 value I’m saving it has to be in a table

Alright then great, good luck.

Essentially what’s happening is that SetAsync expects an array of user IDs as the third argument, and you’re accidentally passing a number value, which isn’t able to be converted to an array, thus the error occurs. This explains why the solution offered by @Amritss worked, since now you’re only passing two arguments to SetAsync (the key, a dictionary containing the number values) instead of three (the key, a number value, another number value)

I don’t remember the exact syntax for setasync but there is a third argument?? Yep turns out there is: GlobalDataStore | Documentation - Roblox Creator Hub

1 Like

From my experience, usually only the first two arguments are used for SetAsync, which is why the other two are often forgotten :sweat_smile:

Thx for the help but I’m now getting an error whenever I load data that says:
value of type table cannot be converted to a number
Anyone know why its showing that?

here’s my loading code: also ik It’s a bit barebones but I’ll be adding pcalls soon
image
Error is on line 15

Replace line 20 with:

Wins.Value = Data and Data.WinsValue or 0

and line 25 with:

Money.Value = Data and Data.MoneyValue or 0

I’ll get back to you if this works

1 Like

Just do something like this after line 16:

if Data then
Wins.Value = Data.WinValue
Money.Value = Data.MoneyValue
end

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.