Anybody know how to make this script do the complete opposite of the 2nd sentence in the brackets? Basically I want the script to let the player have a time on the leaderboard regardless if they die from start to end! People have said “datastore this, bindtoclose that” and nothing’s worked!
This is the script in ServerScriptService
--[[
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("LeaderBoardData")
-- [ 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, please!")
else
num = num * 1000
Store:SetAsync(plr.UserId, num)
end
end
end)
The script I sent above is the script in serverscriptservice so here are the other 2! You’re welcome!
This is the script inside of the leaderboard part that updates the leaderboard:
local DataStoreService = game:GetService("DataStoreService")
-- [ LOCALS ] --
local DataVer = "DataTimer" -- Data Store Name
local Store = DataStoreService:GetOrderedDataStore("LeaderBoardData5")
local RationalDigits = 3 -- How many numbers show.
-- [ FUNCTIONS ] --
function GetLBData()
local success, pages = pcall(function()
return Store:GetSortedAsync(true, 10)
end)
if success and pages then
local topTimes = pages:GetCurrentPage()
for rank, data in pairs(topTimes) do
local val = data.value / 1000
local decimalOffset = math.pow(10, RationalDigits)
local RoundedTime = math.round(val*decimalOffset)/decimalOffset
local splitComplete = tostring(RoundedTime + (1 / (decimalOffset * 10))):split(".")
local PrettyTime = splitComplete[1] .. "." .. splitComplete[2]:sub(0, 3)
script.Parent.SurfaceGui["A" .. tostring(rank)].PlrName.Text = data.key .. ": " .. PrettyTime
end
end
end
GetLBData()
while wait(60) do
pcall(function()
GetLBData()
end)
end
And this is the local script inside of the timerGUI in the screenGUI thing:
--[[
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
If you look in the properties of the ScreenGui, there will be something about reseting on spawn. If you disable that, does it result in the desired outcome?
ResetOnSpawn has been disabled ever since I got the model, but it just doesn’t work either. I know I’ve been annoying people on here, but I’ve tried everything and nothing seems to work
You can locate the code section related to saving the time (ApplyTime) remote event, and event which triggers it (touched event) and add in a new event which triggers on death (humanoid.Died event).
Oh I’m not sure about what I should do in that portion of script and I can’t find it! I have a feeling you were probably talking about the gui one since I see “textlabel” Like I said I’m a beginner and I’m very careful on where stuff goes!
I found the section of code you were talking about! Now I just gotta go in studio and hope I don’t mess anything up lol. I don’t know what to do, what do I change, add? Where?
Can you give a better explanation? Like did you mean if they got to the end, but died; it would still show the time it took them to get there as the best time or what?
Nah the complete opposite! If they died during the obby from start to finish they don’t get a time on the leaderboard. But if they don’t die at all they do! If you wanna join the game and test it yourself you can! I’ll let you fly to the end yourself😎
All good, I think I understand. Doing this has multiple routes, like detecting if the CharacterRemoved (Most Popular), or check if the Humanoid died, etc. On the server or client (however you handle the times, most likely client then sending it to the server, anyways). Detect once the Character is removed then stop the time and set it to 0 or whatever.
Alright I just got 2 people to test and it doesn’t work now. What in God’s name is goin on? I just wish there was a way that I could rework the serverscriptservice script so it would allow the player to have a time even if they die but everything seems so complicated
Preciate it bacon mane but I went on and removed the leaderboard from my game for now! I’ll put it back as soon as I get the solution for the leaderboard though