Invalid argument #3 (string expected, got Instance)?

Im getting this error and im not sure what it means can someone help me and tell me what it means?

local inventoryString = Instance.new("StringValue")
InventoryStore:OnUpdate(function(decodedData, player)
inventoryString.Value = decodedData --Error here

2 Likes

StringValues are intended to store strings – the error is indicating that “decodedData” is an Instance, which cannot be stored inside of a StringValue. An ObjectValue would be utilized to store a reference to an Instance, instead.

However, I’m not sure what the use case for this is, so keep in mind that there may be better alternatives for what you’re trying to do.

1 Like

what is a better alternative instead of decodedData?

Try tostring(decodedData), this will convert decodedData to a string

I tried that but it says this now, i can just make a new post about it, but i think it would be spam but im not sure
Screen Shot 2021-03-19 at 6.41.18 PM

what type is decodedData ?
Check using print(type(decodedData) – If it’s not a string then It wouldn’t work

it prints “userdata”

do
print(decodedData.ClassName)
tell me the output

it prints “Model”

Ohhhh you’re trying to save instances to a datastore?

i can’t use datatstore2?

you can you just can’t store instances

oh, how would i save this type of stuff then?

Since you can’t save the object itself into a DataStore, you could store some data that’ll be used to identify the item, such as its name.

Here’s a fantastic thread which covers this topic:

my man, I was just about to post that lol

1 Like

what if my item is a model?

A Model is still an Instance, which means that some form of serialization would be required.

Any object that you create using the Instance.new() function, is literally an Instance as the function itself states

That’s not true. There are NotCreatable objects.

1 Like