Hello! So I am trying to make DataSave for "playing time". But, I am getting error for 22nd line:
WHOLE SCRIPT:
local DataStore = game:GetService("DataStoreService"):GetDataStore("TimeDataStore")
local timeName = "Time"
game.Players.PlayerAdded:Connect(function(player)
local load = player:WaitForChild("leaderstats")
local leaderstats = player.leaderstats
if load then
leaderstats:WaitForChild("Cash")
local Timing = Instance.new("IntValue")
Timing.Parent = leaderstats
Timing.Name = timeName
end
local ID = timeName.."-"..player.UserId
local DataSave = nil
pcall(function()
DataSave = DataStore:GetAsync(ID)
end)
if DataSave ~= nil then
timeName.Value = DataSave
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local ID = timeName.."-"..player.UserId
DataStore:SetAsync(ID,player.leaderstats[timeName].Value)
end)
game:BindToClose(function()
for i, player in pairs(game.Players:GetPlayers()) do
if player then
player:Kick("This server is shutting down")
end
end
wait(3)
end)
and problem is:
if DataSave ~= nil then
timeName.Value = DataSave
end
I don't know, why is this happening, it's just a variable. Are there any solutions for that?

1 comment
I understand that, but on other kinda same script (just different value), it's working okay: (I posted it below)