Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Why isn't this data store saving? The Pcall says it is working

Asked by 3 years ago
01local ds = game:GetService("DataStoreService")
02local player = game:GetService("Players")
03local rep =  game:GetService("ReplicatedStorage")
04local statsf = rep:WaitForChild("Stats")
05local datastore = ds:GetDataStore("Stats")
06local function saveData(player)
07    local speed = statsf:WaitForChild(player.Name):WaitForChild("Speed")
08    local strength = statsf:WaitForChild(player.Name):WaitForChild("Strength")
09    local data = {
10        speed.Value,
11        strength.Value
12    }
13 
14    local success, err = pcall(function()
15        datastore:SetAsync(player.UserId, data)
View all 79 lines...

Also, if there is any way to improve upon this script, let me know! Thank you

1 answer

Log in to vote
1
Answered by
Xapelize 2658 Moderation Voter Community Moderator
3 years ago
Edited 3 years ago

I think you are trying to save a table. Try to do this on line 14 to 16:

1local success, err = pcall(function()
2    datastore:SetAsync(player.UserId.. " speed", data[1]
3    datastore:SetAsync(player.UserId.. " strength", data[2]
4end)

Since you used the same key, and saved strength after speed, so your speed key will overlapped by the strength value (i think this is one of the problem, though), so you should consider use 2 different keys (your data will reset, sorry lol)

0
thanks for the quick reply! I have just swapped over to datastore2 DesiredRep 75 — 3y
Ad

Answer this question