Ad
Log in to vote
0

Why does Roblox give a random number to a datastore?

Asked by 3 days ago

I didn't really know how to word this question but I think I did an ok job, anyway every time I enter the game, it gives me a random number, normally the random number is higher than the previous number, a follow up question would be, do I need separate data stores for separate values?

secStore = game:GetService("DataStoreService"):GetDataStore("DataStore")


function PlayerEntered(player)
    repeat wait() until player.Character

    local stats = Instance.new("IntValue")
    stats.Parent = player 
    stats.Name = "leaderstats"

    local sec = Instance.new("IntValue")
    sec.Name = "Seconds"
    sec.Value = 0
    sec.Parent = stats

    local min = Instance.new("IntValue")
    min.Name = "Minutes"
    min.Value = 0
    min.Parent = stats

    local hur = Instance.new("IntValue")
    hur.Name = "Hours"
    hur.Value = 0
    hur.Parent = stats


    --saves

    if secStore:GetAsync("Points_"..player.Name) ~= nil then 
        sec.Value = secStore:GetAsync("Points_"..player.Name)
    else
        sec.Value = 0
    end

    sec.Changed:connect(function(Val)
        secStore:SetAsync("Points_"..player.Name, Val)

    end)

    if secStore:GetAsync("Points_"..player.Name) ~= nil then 
        min.Value = secStore:GetAsync("Points_"..player.Name)
    else
        min.Value = 0
    end

    min.Changed:connect(function(Val)
        secStore:SetAsync("Points_"..player.Name, Val)

    end)

    if secStore:GetAsync("Points_"..player.Name) ~= nil then 
        hur.Value = secStore:GetAsync("Points_"..player.Name)
    else
        hur.Value = 0
    end

    hur.Changed:connect(function(Val)
        secStore:SetAsync("Points_"..player.Name, Val)

    end)    


    --loops


    while wait(1) do
        sec.Value = sec.Value+1
    end

    if sec.Value == 60 or sec.Value > 60 then
        min.Value = min.Value + 1
    end

    if min.Value == 60 or min.Value > 60 then
        hur.Value = hur.Value + 1
    end
end

game.Players.PlayerAdded:connect(PlayerEntered)


Answer this question