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

Best ways of tracking time on a game?

I have a problem, I want to track the amount of time a player spends on my game, and then upload it to a google sheets table when they leave. The time the player spends in the game is kept inside an Intvalue which I need to constantly update. I've attempted to use things like Time and tick but those don't seem to work. Any other ideas on how to track time a player spent in a game using my Intvalue system?

2 comments

0

no need to use time or tick if it's simply keeping track of seconds played. and use datastore.

3 answers

✓ Accepted answer

Didn't fully test this, but this should be around the answer you're looking for. :)

local playerTracker = {}

game.Players.PlayerAdded:connect(function(player)
	playerTracker[player] = 0
	
	spawn(function()
		while wait(1) do
			for i, data in pairs(playerTracker) do
				data = data + 1
			end
		end
	end)
end)

game.Players.PlayerRemoving:connect(function(player)
	local data = playerTracker[player]
	
	--Store data to Google here
end)

1 comment

0

There is no need to have a loop per player

Here, do this, I put a variable which will make the timer subtract itself by one

local a = 10  -- change to what ever time...

repeat
	wait(1) -- Every second    this helps the the timer go down by one
	-- Place Stuff  (Put your code in here, what ever you want)
	a = a - 1     -- don't change  or else the timer won't work unless you change the -1 to something else.
	print(a)   -- Check to see if it works..
until a == 0

where it says "Place stuff", put your code their.

I hope this helps, accept answer if it does.

(script in workspace)

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