How to time how long someone has made contact to a part

I’m trying to time how long someone has made contact to a part but i don’t know how to link the function hit to the leaderstats (I don’t know how to add onto the leaderboard)
I’m very new to lua

This script is for the part
image

This is script is for the leaderboard
image

local part = workspace.Block
local TouchedData = {}
part.Touched:Connect(function(hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if not player then return end
	local Found = false
	for _,v in pairs(TouchedData) do
		if v[1]==player then
			Found = true
		end
	end
	if not Found then
		table.insert(TouchedData,{player,os.time()})
	end
end)
part.TouchEnded:Connect(function(hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if not player then return end
	for i,v in pairs(TouchedData) do
		if v[1]==player then
			v[1].leaderstats.Time.Value+=os.time()-v[2]
			table.remove(TouchedData,i)
		end
	end
end)

Try this script for the part.

1 Like

I’ve tried it and the leaderboard doesn’t update, i’ve looked through the script and couldn’t find the problem : /