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

How would I use datastore for this?

Asked by 9 years ago

I'm making a place that will be like the future and I want to keep track of the time each player spends on my game. I need to use datastore, but I have barely any experience with it. Here is my code I edited from the wiki:

local stats = {"Hours", "Minutes", "Seconds"}

game.Players.PlayerAdded:connect(function(player)
    local leaderstats = Instance.new("Model", player)
    leaderstats.Name = "leaderstats"
while wait(1) do 
    for _,Player in pairs(game.Players:GetPlayers()) do
        if Player:FindFirstChild("leaderstats") then
            Player.leaderstats.Seconds.Value = Player.leaderstats.Seconds.Value +1 -- add a second
        end
if Player.leaderstats.Seconds.Value == (60) then -- convert seconds to minutes
Player.leaderstats.Seconds.Value = (0)
Player.Leaderstats.Minutes.Value = Player.leaderstats.Minutes.Value +1
end
if Player.leaderstats.Minutes.Value == (60) then -- convert minutes to hours
Player.leaderstats.Minutes.Value = (0)
Player.leaderstats.Hours.Value = Player.leaderstats.Hours.Value +1
end
    for _, stat in pairs(stats) do
        Instance.new("IntValue", leaderstats).Name = stat 
-- datastore goes here
end
end
end
end)

Thanks for reading! And please post some wiki articles if you can!

0
I have a script in serverscriptservice. TroytheDestroyer 75 — 9y

Answer this question