local DataStoreService = game:GetService("DataStoreService")
local CyberWorldDatastore = DataStoreService:GetDataStore("CyberWorldDatastore")
game.Players.PlayerAdded:Connect(function(player)
local folder = Instance.new("Folder")
folder.Name = "Data"
folder.Parent = player
local TimesJoined = Instance.new("IntValue")
TimesJoined.Name = "TimesJoined"
TimesJoined.Parent = folder
local Credits = Instance.new("IntValue")
Credits.Name = "Credits"
Credits.Parent = folder
local data
local success, errormessage = pcall(function()
data = CyberWorldDatastore:GetAsync(player.UserId)
end)
if success then
TimesJoined.Value = data
Credits.Value = data
print("data successfully loaded")
else
print("an error occured")
warn(errormessage)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local data = {
TimesJoined = player.Data.TimesJoined;
Credits = player.Data.Credits;
}
local success, errormessage = pcall(function()
CyberWorldDatastore:SetAsync(player.UserId, data)
end)
if success then
print("Data succesfuly saved")
else
print("error")
warn(errormessage)
end
end)
Does anyone know what a UTF-8 is and how to use it?
Thanks for reading,
Theyoloman1920
UTF-8 is just an encoding format. Any characters that can be written can be encoded. But you can’t encode a whole object, as it can be composed of many different data types beyond characters.
local data = {
TimesJoined = player.Data.TimesJoined;
Credits = player.Data.Credits;
}
If you look at the data your are attempting to store the value instance themselves and not whats inside which is not acceptable as data storage. We can see this by simply looking up what UTF-8 is which is described as this by a quick google search.
"UTF-8 is a variable-width character encoding capable of encoding all 1,112,064 valid character code points in Unicode using one to four one-byte code units. "
It basically is the way that encoding data stores work so when you try to throw the object of the value instead of the value itself roblox data stores do not recognize that kind of data as it is not acceptable as UTF-8 hence it gieves you the error. So you can try switching it out with .Value when you save. Dont forget to mark this as a solution
well the issue he is having is witht he values not with json encoding so encoding data doesnt really solve anything in this situation. But like I said before roblox automatically encodes the tables in json format so it is unneeded.
Thank you all for replying. I really don’t know which is the right solution, as I have no idea how to do any of these things you told me. I am not that advanced in scripting and I learned about datastores today. Could someone give me a step by step process of what I have to do in order to fix it?
game.Players.PlayerRemoving:Connect(function(player)
local data = {
TimesJoined = player.Data.TimesJoined.Value; -- You need to encode the value, you can't encode an object
Credits = player.Data.Credits.Value;
}
Now that I did this, the data won’t save at all… I see no error nor any “data successfully saved” message. And when I check, the data are not saved. And yes, I do it from the server side…