---###----------[[DESCRIPTION]]----------###---
I've been working on a game and I just recently tested how the DataStore is going and if it works and it turns out it doesn't save at all and I get no error. What is the problem with my DataStore and why won't it save?
---###----------[[UPDATE]]----------###---
I forgot you could test DataStores in studio so I tested it and I got the error "104: Cannot store Array in data store. Datastores can only accept valid UTF-8 characters.", but I have no idea what it means and I don't know what UTF-8 characters are.
P.S. I haven't scripted in about a year and I never really used tables so if I used them wrong please tell me and explain what I got wrong!
---###----------[[SCRIPT]]----------###---
--###----------[[SERVICES]]----------###-- local Players = game:GetService("Players") local TweenService = game:GetService("TweenService") local DataStoreService = game:GetService("DataStoreService") local ReplicatedStorage = game:GetService("ReplicatedStorage") --###----------[[DATASTORES]]----------###-- local LeaderBoard1DS = DataStoreService:GetDataStore("LeaderBoard1DS") --###----------[[LEADERBOARD]]----------###-- Players.PlayerAdded:Connect(function(player) local leaderstats = Instance.new("Folder", player) leaderstats.Name = "leaderstats" --###----------[[BUXSTATS]]----------###-- local BuxStats = Instance.new("Folder", leaderstats) BuxStats.Name = "BuxStats" --###----------[[OTHERSTATS]]----------###-- local OtherStats = Instance.new("Folder", leaderstats) OtherStats.Name = "OtherStats" --###----------[[BUX]]----------###-- local Bux = Instance.new("NumberValue", leaderstats) Bux.Name = "Bux" Bux.Value = 10000 --###----------[[GAMEPASSES]]----------###-- local Gems = Instance.new("NumberValue", leaderstats) Gems.Name = "Gems" --###----------[[KILLS]]----------###-- local Rap = Instance.new("NumberValue", leaderstats) Rap.Name = "Rap" Rap.Value = 0 --###----------[[ADDBUX]]----------###-- local AddBux = Instance.new("NumberValue", BuxStats) AddBux.Name = "AddBux" AddBux.Value = 50 --###----------[[UPGRADECOST]]----------###-- local BuxCost = Instance.new("NumberValue", BuxStats) BuxCost.Name = "BuxCost" BuxCost.Value = 5000 --###----------[[TITLE]]----------###-- local Title = Instance.new("StringValue", OtherStats) Title.Name = "Title" Title.Value = "" --###----------[[CASESPEED]]----------###-- local CaseSpeed = Instance.new("NumberValue", OtherStats) CaseSpeed.Name = "CaseSpeed" CaseSpeed.Value = 10 --###----------[[CASESPEEDCOST]]----------###-- local CaseSpeedCost = Instance.new("NumberValue", OtherStats) CaseSpeedCost.Name = "CaseSpeedCost" CaseSpeedCost.Value = 25000 --###----------[[MULTIPLIER]]----------###-- local Multiplier = Instance.new("NumberValue", OtherStats) Multiplier.Name = "Multiplier" Multiplier.Value = 1 end) --###----------[[LEADERBOARDDS/DATASTORES]]----------###-- Players.PlayerAdded:Connect(function(player) local PlayerGui = player:WaitForChild("PlayerGui") wait() local plrkey = "id_"..player.userId local LeaderStats = { LeaderStats1 = player.leaderstats.Bux, LeaderStats2 = player.leaderstats.Gems, BuxStats1 = player.leaderstats.BuxStats.AddBux, BuxStats2 = player.leaderstats.BuxStats.BuxCost, OtherStats1 = player.leaderstats.OtherStats.CaseSpeed, OtherStats2 = player.leaderstats.OtherStats.CaseSpeedCost } local GetSaved = LeaderBoard1DS:GetAsync(plrkey) if GetSaved then LeaderStats.LeaderStats1.Value = GetSaved[1] LeaderStats.LeaderStats2.Value = GetSaved[2] LeaderStats.BuxStats1.Value = GetSaved[3] LeaderStats.BuxStats2.Value = GetSaved[4] LeaderStats.OtherStats1.Value = GetSaved[5] LeaderStats.OtherStats2.Value = GetSaved[6] else local NumberForSaving = { LeaderStats.LeaderStats1.Value, LeaderStats.LeaderStats2.Value, LeaderStats.BuxStats1.Value, LeaderStats.BuxStats2.Value, LeaderStats.OtherStats1.Value, LeaderStats.OtherStats2.Value } LeaderBoard1DS:SetAsync(plrkey, NumberForSaving) end end) Players.PlayerRemoving:Connect(function(player) LeaderBoard1DS:SetAsync("id_"..player.userId, {player.leaderstats.Bux.Value, player.leaderstats.Gems.Value, player.leaderstats.BuxStats.AddBux.Value, player.leaderstats.BuxStats.BuxCost.Value, player.leaderstats.OtherStats.CaseSpeed, player.leaderstats.OtherStats.CaseSpeedCost}) end)
You can't save userdata to Datastores. Values such as Vector3 or NumberValue can't be saved to Datastores.
tables can be saved to DataStores, however they have to have valid elements.