So I really want to make it so that a numbervalue will save! I tried editing many datastore scripts and it didn’t save. I don’t really know how to fix it to save for a player so help will be greatly appreciated!!
function onPlayerEntered(newPlayer)
wait(.5)
local Time = Instance.new("NumberValue")
Time.Name = "Timer"
Time.Value = 0
Time.Parent = newPlayer
while true do
wait(1)
Time.Value = Time.Value +1
end
end
game.Players.ChildAdded:connect(onPlayerEntered)
(script above is just the basic time script)
I don’t have the datastore script anymore because I deleted it…
just turn it into a dictionary like: local save = {["Timer"] = Time.Value}
JSONEncode it, save it to datastore
when you fetch it back, decode it, then reference it as: Time.Value = save["Timer"]
then the numbervalue will be set to what it was when it was saved.
I don’t recommend running a loop for every player to track this though. It would be cleaner to take a time reference like os.time() when the player joins and again when they leave, subtract the first from the second to get the total amount of seconds they were on the server, then save that. Actually, no reason for a numbervalue at all if you did it that way, may be the way to go?