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

Why doesnt my save data storage work?

Asked by 7 years ago
Edited 7 years ago

I tried using save storage for the first time but sadly it wont save the data at all

local DataStore =  game:GetService("DataStoreService"):GetDataStore("Time")

game.Players.PlayerAdded:connect(function(player)

local stats = Instance.new("Model", player)
stats.Name = "leaderstats"

local seconds = Instance.new("IntValue", player.leaderstats)
seconds.Name = "Seconds"

local minutes = Instance.new("IntValue", player.leaderstats)
minutes.Name = "Minutes"

local hours = Instance.new("IntValue", player.leaderstats)
hours.Name = "Hours"

--

local key = "player-"..player.userId

local savedV = DataStore:GetAsynt(key)

if savedV then
-- {seconds, minutes, hours}
 seconds.Value = savedV[1]
 minutes.Value = savedV[2]
 hours.Value = savedV[3]
else
    local valuesToSave = {seconds.Value, minutes.Value, hours.Value}
    DataStore:SetAsync(key, valuesToSave)
end

end)

leave script

local DataStore =  game:GetService("DataStoreService"):GetDataStore("Time")

game.Players.PlayerRemoving:connect(function(player)

    local key = "player-"..player.userId
    local valuesToSave = {player.leaderstats.seconds.Value, player.leaderstats.minutes.Value, player.leaderstats.hours.Value}
    DataStore:SetAsync(key, valuesToSave)

end)
0
You have not saved the data when the player leaves the game. User#5423 17 — 7y
0
You accidentally typed :GetAsynt in line 21 joalars2 107 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

I also did this



local DataStore = game:GetService("DataStoreService"):GetDataStore("Time") game.Players.PlayerRemoving:connect(function(player) local key = "player-"..player.userId local valuesToSave = {player.leaderstats.seconds.Value, player.leaderstats.minutes.Value, player.leaderstats.hours.Value} DataStore:SetAsync(key, valuesToSave) end)
Ad

Answer this question