Table not converting data?

I’m making an activity tracker for my game. I know the basics and I know how this will turn out, however I’m running into this one issue.

Upon joining, the game stores your name into a table. Your name is also associated with the Tolerance and Seconds properties. Tolerance determines whether to count seconds or not.

PlayerAdded Script:

		spawn(function()
			if Player:GetRankInGroup(sysTable.groupId) >= 8 then
				sysTable.baristaActivityTable[Player.Name] = {false, 0}
				local Tolerance = sysTable.baristaActivityTable[Player.Name][1]
				local Seconds = sysTable.baristaActivityTable[Player.Name][2]
				Tolerance = true
				repeat
					Seconds += 1
					wait(1)
				until not Tolerance
			end
		end)

PlayerRemoving Script:

		if sysTable.baristaActivityTable[Player.Name] then
			local Tolerance = sysTable.baristaActivityTable[Player.Name][1]
			local Seconds = sysTable.baristaActivityTable[Player.Name][2]
			Tolerance = false
			print(Seconds)
			if Seconds > 10 then
				local convertedSeconds = timeAndDate.Time(Seconds)
				local convertedDate = timeAndDate.Date()
				sendActivity(Player, convertedSeconds, convertedDate)
			end
			sysTable.baristaActivityTable[Player.Name] = nil
		end

The issue here, is that it is printing 0 when it says print(Seconds) in the PlayerRemoving script. It should print the amount of seconds the player was in-game, according to the PlayerAdded script.

Any way to fix this?

i think

					Seconds += 1

should be replaced with:

					Seconds = Seconds + 1

if this does not work then try to check if value is even there. if you still read 0 or nil then seconds are not properly placed in table

Seconds is just a copy of sysTable.baristaActivityTable[Player.Name][2], not a reference. Same issue with Tolerance.

Instead try:
PlayerAdded Script :

 spawn(function()
		if Player:GetRankInGroup(sysTable.groupId) >= 8 then
			sysTable.baristaActivityTable[Player.Name] = tick()
   		end
end)

PlayerRemoving Script :

		if sysTable.baristaActivityTable[Player.Name] then
			local Seconds = tick() - sysTable.baristaActivityTable[Player.Name]
			
			print(Seconds)
			if Seconds > 10 then
				local convertedSeconds = timeAndDate.Time(Seconds)
				local convertedDate = timeAndDate.Date()
				sendActivity(Player, convertedSeconds, convertedDate)
			end
			sysTable.baristaActivityTable[Player.Name] = nil
		end
2 Likes

Seconds += 1 would wokr roblox added this feature

Sorry for the late reply, I was sleeping. Thanks, this worked!! :happy3: