It won’t add the stats.
Server Sided:
finishedRemote.OnServerEvent:Connect(function(player, Time)
local BestTimeStat = player.leaderstats.BestTime
Time = tonumber(Time)
if BestTimeStat.Value > Time and BestTimeStat.Value ~= 0 and game.Workspace.Level1.Stop.Touched == true then
BestTimeStat.Value = Time
print("Set the stats")
elseif BestTimeStat.Value < Time and BestTimeStat.Value ~= 0 and game.Workspace.Level1.Stop.Touched == true then
print("To slow")
elseif BestTimeStat.Value == 0 and game.Workspace.Level1.Stop.Touched == true then
BestTimeStat.Value = Time
end
end)
Client
local player = game:GetService("Players").LocalPlayer
local TimeText = script.Parent.TimeText
local Playing = script.Parent.Parent.Parent:WaitForChild("Playing")
local Time = 0
local finishedRemote = game:GetService("ReplicatedStorage"):WaitForChild("finishedTime")
local RationalDigits = 2
local Accuracy = 10^RationalDigits
local function roundTimer()
local Div1 = math.abs(tick() - current_time)
local CalculatedIncrement = math.round(Div1*Accuracy)/Accuracy
local Addons={}
for t=1,RationalDigits do
local i = t-1
local integer,predecimal = math.modf(CalculatedIncrement*(10^i))
local decimal = predecimal/(10^i)
if decimal == 0 then
Addons[t] = "0"
end
end
NewText = tostring(CalculatedIncrement)
for i,v in pairs(Addons) do
NewText = NewText..v
end
TimeText.Text = NewText
end
TimerOn = false
while wait() do
if Playing.Value == true then
current_time = tick()
TimerOn = true
break
else
TimerOn = false
end
end
while TimerOn == true do
if Playing.Value == true then
TimeText.TextColor3 = Color3.new(255, 255, 255)
TimeText.Visible = true
TimeText.Text = Time.."s"
wait(0.1)
roundTimer()
Time = NewText
elseif Playing.Value == false then
local Time = (tick() - current_time)
finishedRemote:FireServer(Time)
TimeText.TextColor3 = Color3.new(0, 255, 0)
TimerOn = false
TimeText.Visible = false
Time = 0
break
end
end