104: Cannot save Instance in DataStore

SO… Here I am, with a warning from my data store script:

local dss = game:GetService("DataStoreService")
local leaderstatsStore = dss:GetDataStore("LeaderstatsData1")
local boatsStore = dss:GetDataStore("BoatsData1")

local savedBoats = game.ServerStorage.SavedBoats

game.Players.PlayerAdded:Connect(function(plr)
	local boat = nil
	boat = boatsStore:GetAsync(plr.UserId)
	
	if boat ~= nil then
		boat.Parent = workspace.Boats
		boat.Owner.Value = plr.Name -- making sure the boat's name is the player's name
		boat.Name = plr.Name.."'s Boat"
	else
		--boat is nil, new player
		--we will give them a starter boat
		local starterBoat = savedBoats.Starter:Clone()
		starterBoat.Parent = workspace.Boats
		starterBoat.Owner.Value = plr.Name
		starterBoat.Name = plr.Name.."'s Boat"
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	for i, boat in pairs(workspace.Boats:GetChildren()) do
		if boat.Owner.Value == plr.Name then
			local success, errmess = pcall(function()
				boatsStore:SetAsync(plr.UserId, boat)
			end)
			
			if success then
				print("Data saved successfully")
			else
				warn(errmess)
			end
		end
	end
end)

The warning comes here:

if success then
	print("Data saved successfully")
else
	warn(errmess) -- HERE!
end


Is this because I am testing in Studio? Or is it just that I CAN’T store Instances in a DataStore?

You just can’t store instances in data stores.

If they’re premade boats, just save the name. Otherwise, you’ll probably have to store the properties of each of the parts in the boat.

4 Likes