Error when trying to save multiple values in a Datastore

I am trying to save stat values in my datastore, player position, and some others.

When running with all of them I get the error “Unable to cast value to Object.” I think I may be trying to save too many slots of data?

I have tried using all of them individually, such as (AttackValue, scope), and they all went without errors.

Script
local function Datastore(player)

	local scope = player.UserId
	local Attack = player:WaitForChild("Attack")
	local AttackValue = Attack.Value

	local Intellect = player:WaitForChild("Intellect")
	local IntellectValue = Intellect.Value

	local Dexterity = player:WaitForChild("Dexterity")
	local DexterityValue = Dexterity.Value

	local Defense = player:WaitForChild("Defense")
	local DefenseValue = Defense.Value

	local Profession = player:WaitForChild("Profession")
	local ProfessionValue = Profession.Value
	
	local Loarxion = player:WaitForChild("Loarxion")
	local LoarxionValue = Loarxion.Value
	
	local HumanoidRootPart = player.Character:FindFirstChild("HumanoidRootPart")
	if HumanoidRootPart then
		local HumanoidRootPartLocation = HumanoidRootPart.Position
		local Location = {HumanoidRootPartLocation.X, HumanoidRootPartLocation.Y, HumanoidRootPartLocation.Z}

		local playerStats = DataStoreService:GetDataStore(AttackValue, IntellectValue, DexterityValue, DefenseValue, ProfessionValue, LoarxionValue, Location, scope)
	print("OK")
1 Like

A few things:

1- you’re passing instances to the GetDataStore method, it requires a string.
2- you’re passing too many arguments to the GetDataStore method, it requires 3: the name of the datastore, the scope, and the options.
3- I think you would want to use :GetAsync as :GetDataStore returns a global datastore (which can be looked at as a big table of data whose keys are the players’ keys whereas :GetAsync returns the actual player’s data.
4- You probably want to save all of your data in one table.

I didn’t realize number 2, thx for pointing that out

1 Like