How come my DataStore won't save said values needed to be saved?
Asked by
3 years ago Edited 3 years ago
---###----------[[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]]----------###---
02 | local Players = game:GetService( "Players" ) |
03 | local TweenService = game:GetService( "TweenService" ) |
04 | local DataStoreService = game:GetService( "DataStoreService" ) |
05 | local ReplicatedStorage = game:GetService( "ReplicatedStorage" ) |
07 | local LeaderBoard 1 DS = DataStoreService:GetDataStore( "LeaderBoard1DS" ) |
09 | Players.PlayerAdded:Connect( function (player) |
10 | local leaderstats = Instance.new( "Folder" , player) |
11 | leaderstats.Name = "leaderstats" |
13 | local BuxStats = Instance.new( "Folder" , leaderstats) |
14 | BuxStats.Name = "BuxStats" |
16 | local OtherStats = Instance.new( "Folder" , leaderstats) |
17 | OtherStats.Name = "OtherStats" |
19 | local Bux = Instance.new( "NumberValue" , leaderstats) |
23 | local Gems = Instance.new( "NumberValue" , leaderstats) |
26 | local Rap = Instance.new( "NumberValue" , leaderstats) |
30 | local AddBux = Instance.new( "NumberValue" , BuxStats) |
31 | AddBux.Name = "AddBux" |
34 | local BuxCost = Instance.new( "NumberValue" , BuxStats) |
35 | BuxCost.Name = "BuxCost" |
38 | local Title = Instance.new( "StringValue" , OtherStats) |
42 | local CaseSpeed = Instance.new( "NumberValue" , OtherStats) |
43 | CaseSpeed.Name = "CaseSpeed" |
46 | local CaseSpeedCost = Instance.new( "NumberValue" , OtherStats) |
47 | CaseSpeedCost.Name = "CaseSpeedCost" |
48 | CaseSpeedCost.Value = 25000 |
50 | local Multiplier = Instance.new( "NumberValue" , OtherStats) |
51 | Multiplier.Name = "Multiplier" |
55 | Players.PlayerAdded:Connect( function (player) |
56 | local PlayerGui = player:WaitForChild( "PlayerGui" ) |
58 | local plrkey = "id_" ..player.userId |
60 | LeaderStats 1 = player.leaderstats.Bux, |
61 | LeaderStats 2 = player.leaderstats.Gems, |
62 | BuxStats 1 = player.leaderstats.BuxStats.AddBux, |
63 | BuxStats 2 = player.leaderstats.BuxStats.BuxCost, |
64 | OtherStats 1 = player.leaderstats.OtherStats.CaseSpeed, |
65 | OtherStats 2 = player.leaderstats.OtherStats.CaseSpeedCost |
68 | local GetSaved = LeaderBoard 1 DS:GetAsync(plrkey) |
70 | LeaderStats.LeaderStats 1. Value = GetSaved [ 1 ] |
71 | LeaderStats.LeaderStats 2. Value = GetSaved [ 2 ] |
72 | LeaderStats.BuxStats 1. Value = GetSaved [ 3 ] |
73 | LeaderStats.BuxStats 2. Value = GetSaved [ 4 ] |
74 | LeaderStats.OtherStats 1. Value = GetSaved [ 5 ] |
75 | LeaderStats.OtherStats 2. Value = GetSaved [ 6 ] |
77 | local NumberForSaving = { |
78 | LeaderStats.LeaderStats 1. Value, |
79 | LeaderStats.LeaderStats 2. Value, |
80 | LeaderStats.BuxStats 1. Value, |
81 | LeaderStats.BuxStats 2. Value, |
82 | LeaderStats.OtherStats 1. Value, |
83 | LeaderStats.OtherStats 2. Value |
85 | LeaderBoard 1 DS:SetAsync(plrkey, NumberForSaving) |
88 | Players.PlayerRemoving:Connect( function (player) |
89 | LeaderBoard 1 DS: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 } ) |