Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why doesnt my save data storage work?

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)

2 comments

0

You have not saved the data when the player leaves the game.

0

You accidentally typed :GetAsynt in line 21

1 answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.