Getting Offline Player's Leaderstats

I have a script where I simply remove some time off a group reward timer, but this is while the player is ingame, not offline or anything. How do I make it so it removes time to offline people?

game.Players.PlayerAdded:Connect(function(plr)
	while true do
		wait(1)
		if plr.RewardsCooldown.GroupReward.Value ~= 0 then
			plr.RewardsCooldown.GroupReward.Value -= 1
			print(plr.RewardsCooldown.GroupReward.Value)
		end
	end
end)

not sure if you need this but here.

1 Like

You could store the time of when the player left using os.time and the GroupRewards value as well. And when they join, subtract the GroupRewards by how long they were offline in the game. Which is the current time minus the time that the player left.

Use os.time on the server to prevent Date and Time change exploits

1 Like

You can save the time and the date and when player join check if the time and date still didn’t finish then make the countdown or whatever you are doing.

Edited: kexy123 already solve it.

should i make another saved value in the player as “TimePlayerLeft”?
and it’ll reset every time they join? (after subtracting time from groupRewards.

You can calculate the TimePlayerLeft by subtracting the time they joined by the time they left, therefore you don’t need to save a variable to do that.

then, how would I get the time they left without saving it?

edit 1: btw the solution kinda works, afew tries after though it fails to load TimePlayerLeft, and it subtracts ALOT because of me using os.difftime(). So maybe storing a value wasn’t the best idea.

edit 2: nvm, my script works now, I had a PlayerRemoving function after a while true do loop.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.