Help with DataStores!

Here’s my code:

local mods = game:GetService("DataStoreService"):GetDataStore("mods")
mods:SetAsync(mod_name,encoded,player.UserId)

encoded is a string value.

When this script runs, I get this error message:

image

Can someone please tell me what is wrong, and how to fix it?

How are you defining player?

event1.OnServerEvent:Connect(function(player)
	print(player.UserId)
	a:UploadMod("test",workspace.TestMod,player.UserId)
end)

It’s coming from a RemoteEvent
“a” is my module script! That’s how it’s running this

is the code in the original post part of the function :UploadMod?

Maybe check what happens when u try to print player.Name

:UploadMod is from a module script with the original script for saving the DataStore

When calling the :UploadMod function, you are parsing the UserID. Then within the UploadMod function, you are trying to get the UserID… of the UserID.
Remove .UserID from one of them and it should work

I just fixed that part, but now from this part of my code:

local encoded = serialize.Encode(model,true)
mods:SetAsync(mod_name,encoded,player.UserId)

(the module script code)

It returns this error:

image

EDIT: I fixed the “Unable to cast to Array” by switching my data to a table!
Thank you for helping with the first error, I didn’t even think about that!

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