Hi, I’m repliicated, and yesterday I was following a tutorial about making a datastore. After doing everything, I was excited to try it out. Then, when I “left” the game, it warned me in the output:
Cannot store Instance in data store. Data stores can only accept valid UTF-8 characters.
I would like help, because I don’t think players will be happy if they can’t save their data in my mediocre Break Your Neck Joint Simulator! (lol).
Here is my code if it helps:
local DataStoreService = game:GetService("DataStoreService")
local CountClicks = DataStoreService:GetDataStore("NeckBroken")
game.Players.PlayerAdded:Connect(function(player)
local startingclicks = 0
local leaderstats = Instance.new("Folder")
leaderstats.Name = 'leaderstats'
leaderstats.Parent = player
local clicks = Instance.new("IntValue")
clicks.Name = 'Times Broken Neck'
clicks.Value = startingclicks
clicks.Parent = leaderstats
local PlayerId = "Player_" .. player.UserId
local data
local success, errormessage = pcall(function()
data = CountClicks:GetAsync(PlayerId)
end)
if success then
clicks.Value = data
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local PlayerId = "Player_" .. player.UserId
local data = player.leaderstats["Times Broken Neck"]
local success, errormessage = pcall(function()
CountClicks:SetAsync(PlayerId, data)
end)
if success then
print("Data successfully saved!")
else
print("something wrong bro, this is the problem:")
warn(errormessage)
end
end)