Can someone help with my Data Store problem?
01 | local KEY_PREFIX = "userid_" |
02 | local ds = game:GetService( "DataStoreService" ):GetDataStore( "PlayerValuesDataStore" ) |
03 | local profilesHolder = game.Workspace.Profiles |
06 | function saveToDataStore(plr) |
07 | if Debounce = = true then |
09 | local key = KEY_PREFIX .. tostring (plr.userId) |
10 | local profile = profilesHolder [ plr.Name ] |
12 | for i,v in ipairs (profile:GetChildren()) do |
13 | value [ v.Name ] = v.Value |
14 | print (v.Name .. " = " .. tostring (v.Value)) |
16 | ds:SetAsync(key, value) |
20 | elseif Debounce = = false then |
25 | function loadFromDataStore(plr) |
26 | if Debounce = = true then |
28 | local key = KEY_PREFIX .. tostring (plr.userId) |
29 | local data = ds:GetAsync(key) |
30 | local profile = profilesHolder [ plr.Name ] |
31 | local profileItems = profile:GetChildren() |
32 | for i,v in ipairs (data) do |
33 | profileItems [ i ] .Value = v |
34 | print (i .. " = " .. tostring (v)) |
39 | elseif Debounce = = false then |
44 | game.Players.PlayerAdded:connect( function (player) |
45 | player.Chatted:connect( function (msg) |
47 | if msg = = "/save" then |
48 | saveToDataStore(player) |
49 | elseif msg = = "/load" then |
50 | loadFromDataStore(player) |
This is supposed to go through game.Workspace.Profiles and find all the values then save them and their values to a datastore. The problem is it is not working. It will print out values just fine when it saves, but I don't know if it's actually saving the data to it. Also, it will print "loaded" when I load, but not the loaded values because there is none to load or it is not fetching them properly.
Can someone please help solve this issue?