Datastore: Instance Expected, got String

hey developers, i’ve been working on a datastore which simply saves an objectvalue, but when i try to set the data it just says ‘Instance Expected, got String’.

whats happening

first 2 attempts at running the game, no output, the 3rd attempt it saves the data and the fourth attempt it gives me these errors.

local DSS = game:GetService('DataStoreService')
local invDS = DSS:GetDataStore('InventoryStorage')

game.Players.PlayerAdded:Connect(function(player)
	local Taker1 = Instance.new('ObjectValue', game.StarterGui.Inventory:WaitForChild('InventoryStorageS1').SlotOneData)
	Taker1.Name = 'TakerS1'
	Taker1.Value = game.ServerStorage.CommonTrails.CloudTrail
	
	local data
	local success, errormessage = pcall(function()
		data = invDS:GetAsync(player.UserId..'-isSlot1Taken-dataStoreValue-1726-4914')
	end)

	if success then
		Taker1.Value = data
	else
		game.ReplicatedStorage.Remotes.DataFailed:FireClient(player)
		warn(errormessage)
	end
end)

game.Players.PlayerRemoving:Connect(function(player)

	local success, errormessage = pcall(function()

		invDS:SetAsync(player.UserId..'-isSlot1Taken-dataStoreValue-1726-4914', game:GetService('HttpService'):JSONEncode(game.StarterGui.Inventory.InventoryStorageS1.SlotOneData.TakerS1))
	end)


	if success then
		print('Data Saved Successfully!')
	else
		game.ReplicatedStorage.Remotes.DataFailed:FireClient(player)
		warn(errormessage)
	end

end)

any solutions would be greatly appreciated
cheers

Which line is it exactly that’s giving you the error?

This error means that you attempted to use an Instance in a function or property assignment that expects a string value.

The problem is this line:

Taker1.Value = data

You are attempting to set the value of an ObjectValue to the data given by the datastore GetAsync function which will never be an Instance, as an ObjectValue only accepts Instances and DataStore cannot save Instances. (Taker1 is the ObjectValue here)

1 Like