local DataStoreService = game:GetService("DataStoreService")

local myDataStore = DataStoreService:GetDataStore("AA99")

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

	local datafolder = Instance.new("Folder")
	datafolder.Name = "Data"
	datafolder.Parent = player

	local Grimoire = Instance.new("StringValue")
	Grimoire.Name = "Grimoire"
	Grimoire.Value = "FireGrimoire"
	Grimoire.Parent = datafolder 
	
	local data
	local sucess, errormessage = pcall(function()
		data = myDataStore:GetAsync(player.UserId.."-Grimoire") -- error is in this line
	end)

	if sucess then
		Grimoire.Value = data
		print("Data loaded")
	else
		warn(errormessage)
	end
end)



game.Players.PlayerRemoving:Connect(function(player)
	local sucess, errormessage = pcall(function()
		myDataStore:SetAsync(player.UserId.."-Grimoire",player.Data.Grimoire.Value)
	end)
	if sucess then
		warn("Data saved")
	else
		print("Error Saving Data") -- minor spelling mistake
		warn(errormessage)
	end
end)

1 comment

0

a string was expected in argument #3 but you gave it nil?