Sorry for reposting this but I’m trying to fix a timer in my obby so people can have fun competing. Before you ask, it is not round based! The rest of the scripts for the timer and the leaderboard work perfectly fine but I just wanted the script to do the opposite of what the youtuber put at the top! I want to make it so that even if the player dies from start to finish they can have a time on the leaderboard still. Like I said, it works flawlessly but I just want to make it so that even if the player dies from when they touch the StartTimer and the EndTimer, they can still have a spot on the leaderboard! Only things I changed in this script is the Datastore thingy that says “leaderboardData4” and the Anti-cheat timer! Pay attention to the words at the top of the script please!
--[[
@author TwinPlayzDev_YT
@since 6/1/2021
This script will apply the leaderboard time, and check if a player has finished or completed the obby.
Only saves time when they fully complete course without dieing.
--]]
-- [ SERVICES ] --
local DataStoreService = game:GetService("DataStoreService")
-- [ LOCALS ] --
local DataVer = "[DataTimer]" -- Data Store Name
local Store = DataStoreService:GetOrderedDataStore("LeaderBoardData4")
-- [ FUNCTIONS ] --
_G.ForceSet = function(plrName, newTime)
local num = tonumber(newTime)
num = num * 1000
Store:SetAsync(plrName, num)
end
game.ReplicatedStorage.ApplyTime.OnServerEvent:Connect(function(plr, newTime) -- On Event
local num = tonumber(newTime)
local oldData = Store:GetAsync(plr.UserId)
if oldData then
oldData = oldData / 1000
else
oldData = 1000
end
---- ANTI CHEAT (needs fixing)
if num < oldData then
if num <= 900.00 then
plr:Kick("No cheating bucko!")
else
num = num * 1000
Store:SetAsync(plr.Name, num)
end
end
end)
Yo I’m a beginner scripter and I just wanted to know if I could add that into my local script that I already have here for my timerGUI or do I need to make a separate script somewhere in the workspace?:
--[[
This script handles the touch/stop plates for timer leaderboard.
--]]
-- [ SERVICES ] --
local RunService = game:GetService("RunService")
-- [ LOCALS ] --
local par=script.Parent
local timer=par:WaitForChild'Timer'
local timerlabel=timer:WaitForChild'Time'
local SetTime = tick()
local RationalDigits = 3 -- How many numbers is shown.
local timer_active=false
local timer_time=0
local prev
-- [ FUNCTIONS ] --
function connectplrtouch(pt,func)
pt.Touched:Connect(function(t)
local c=game.Players.LocalPlayer.Character
if c and t:IsDescendantOf(c) then
func()
end
end)
end
for _,d in pairs(workspace:GetDescendants()) do
if d.Name=='TimerStart' then
local name=(d:FindFirstChild'Title' and d.Title:IsA'StringValue' and d.Title.Value) or ''
connectplrtouch(d,function()
par.Enabled=true
if prev~=d then
SetTime = tick()
prev=d
end
--timerlabel.Visible = true
--timer.Visible = true
timerlabel.TextColor3=Color3.new(1, 1, 1)
SetTime = tick()
timer_active=true
end)
end
if d.Name=='TimerEnd' then
connectplrtouch(d,function()
timerlabel.TextColor3=Color3.new(0.172549, 1, 0.027451) -- Finish color
if timer_active == true then
game.ReplicatedStorage.ApplyTime:FireServer(timerlabel.Text)
end
timer_active=false
end)
end
end
local Accuracy = 10^RationalDigits
function TimerFunc()
if timer_active then
local Div1 = math.abs(tick() - SetTime)
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
local NewText = tostring(CalculatedIncrement)
for i,v in pairs(Addons) do
NewText = NewText..v
end
timerlabel.Text=NewText
end
end
while true do
wait(.025)
TimerFunc()
end
I’m assuming that’s in StarterGui. The script mentioned above will not run in StarterGui because when you die things in StarterGui (or any ui in it with RespawnOnSpawn enabled) get reset.
Oh, nah resetonspawn is disabled for the timerGUI. When they walk through the green timer starter it keeps going until they reach the red one which is at stage 100
Looks like the timerlabel.Text … that will fire a remote named ApplyTime.
But there needs to also be a script to pick that up and actually add it to the leaderboard.