Hi guys! In the player, I create a model with different values in them. Instead of individually saving each value, I am trying to put all the values into a table, save that and then load that back into the player when they join the game. I am not 100% about this, and it is not working :/ Any ideas? Thank you very much :) PS: I want to save it as the values change, because if you do it on "PlayerRemoving", sometimes the player can crash and it wont save!
game.Players.PlayerAdded:connect(function(Player)
model = Instance.new("Model")
model.Name = "PlayerModel"
model.Parent = Player
local value = Instance.new("BoolValue")
value.Name = "ValueOne"
value.Parent = model
local lol = Instance.new("IntValue")
lol.Name = "ValueTwo"
value.Parent = model
local dataStore = game:GetService("DataStoreService"):GetDataStore("PlayerModel")
local tab = dataStore:GetAsync("PlayerModel")
for _, child in pairs(model:GetChildren()) do
for _, saved in pairs(tab) do
if rawequal(saved.Name, child.Name) then
child.Value = saved.Value
end
end
end
end)
local dataStore = game:GetService("DataStoreService"):GetDataStore("PlayerModel")
local tab = {}
for _, v in pairs(model:GetChildren()) do
tab[#tab + 1] = {Name = v.Name, Value = v.Value}
end
dataStore:SetAsync("PlayerModel", tab)

18 comments
Thanks for helping! I have edited my post to what I now have! It is still not working though :( Any help would be greatly appreciated!
Data stores are down at the moment, could be the reason why.. I'll take a look, though.
OK! Thanks! :)
OK, thanks for helping although I get these errors :( Bad argument #1 to pairs(table expected, got nil) RbxUtil.DecodeJson expects string argument . RbxUtil.DecodeJson is Deprecated Any ideas? Thanks
I fixed it by setting tab to the returned table or {}
Thanks so much, but I still get the same errors :(
Whatttt! DecodeJSon..(table expected, got nil)??
Yeah :/
finally works! the Utility library only encoded/decoded strings, while HTTP service's actually works with tables.
Thanks! :) let me go and test it..! :D
Thank you so much! It works! :D I just have one more question if you don't mind (I really appreciate all this!) - instead of saving it at gameclose(might not save it the game crashed)... how could I save it each time one of the values changed? (If this is not possible, is there a better way to do this?) Thanks!
Saving it each time a value is changed will most-likely exceed the request limit (depending on how frequently the value changes). If you aren't changing the value too often.. yeah, you can do that.
Well, I am not saving it too often, so it should be fine! :) Do you mind doing that for me? I would really appreciate it! :P Thank you so much for all your help!!
ok
Thanks!! :)
Hmm :( Line 18 and 32 are erroring! :( Any ideas? Thanks!
I once again fixed it. No more edits. Ask another question if you must.
Thank you so much for all your help! :) I really appreciate it!