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

Data store does not save data?

Asked by 6 years ago

I'm trying to save a player's data, but it does not appear to save. It gives no errors, and also used to work. It just randomly stopped working

01local Data = game:GetService("DataStoreService"):GetDataStore("Cash")
02game.Players.PlayerAdded:Connect(function(plr)
03    local Folder = Instance.new("Folder",game.ServerStorage)
04    Folder.Name = plr.Name
05    local Cash = Instance.new("IntValue",Folder)
06    Cash.Name = "Cash"
07    local Levels = Instance.new("IntValue",Folder)
08    Levels.Name = "Levels"
09    local SavedItems = Data:GetAsync(plr.userId)
10    wait(.1)
11    if SavedItems then
12        Cash.Value = SavedItems.Cash or 0
13        Levels.Value = SavedItems.Levels or 0
14    else
15        Cash.Value = 0
View all 25 lines...
0
do you have API services on? mixgingengerina10 223 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

This is probably because the player's UserId is a 64-bit integer. GlobalDataStore:SetAsync() requires a string key.

You can convert the UserId to a string using the tostring() function, like this:

1Data:SetAsync(tostring(plr.UserId), Saving)

Or, you can concatenate the UserId to a string, like this:

1Data:SetAsync("user_" ..plr.UserId, Saving)

#1 is untested. #2 is tested.

Ad

Answer this question