Isn’t storing by name bad practice though?
It is, kind of. There is something else we can do, which is Players:GetNameFromUserIdAsync
if I remember correctly.
Yeah, because if you change your user name then you’ll lose your top time
Preciate you mane! Thank y’all for the help man and have a good night. Its borderline embarrassing asking for a lot of help because when I do try to do coding by myself I mess stuff up. And then y’all make it look so easy!
Where do i put that in this script?
-- [ SERVICES ] --
local DataStoreService = game:GetService("DataStoreService")
-- [ LOCALS ] --
local DataVer = "[DataTimer]" -- Data Store Name
local Store = DataStoreService:GetOrderedDataStore("LeaderBoardData2")
-- [ 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)
It’s not an easy one, but it actually does not seem to go into that script, but rather the one that updates the leaderboard. In this script, you should keep the UserId
version.
Preciate you mane! Y’all have a good night!
Yo MrShowerMan, I know it’s been a few days but how do I fix all these numbers after the decimal here? I only want the first 3 numbers after the decimal point, but I don’t know where to edit it in the code you gave me here. Also, I don’t really want rounded numbers:
local DataStoreService = game:GetService("DataStoreService")
-- [ LOCALS ] --
local DataVer = "DataTimer" -- Data Store Name
local Store = DataStoreService:GetOrderedDataStore("LeaderBoardData4")
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 PrettyTime = tostring(RoundedTime + (1 / (decimalOffset * 10))):sub(0, -2)
script.Parent.SurfaceGui["A" .. tostring(rank)].PlrName.Text = data.key .. ": " .. PrettyTime
end
end
end
GetLBData()
while wait(60) do
pcall(function()
GetLBData()
end)
end
This code should fix that Issue. You essentially had something called Floating Point Error that occurs when you do asthmatic with values that are less then one. To counter act this issue I just remove the extra digits that weren’t needed.
local DataStoreService = game:GetService("DataStoreService")
-- [ LOCALS ] --
local DataVer = "DataTimer" -- Data Store Name
local Store = DataStoreService:GetOrderedDataStore("LeaderBoardData4")
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
``
Thanks man, also I found a random remoteevent in replicatedstorage that I had to delete! I thought that was what was wrong with my main script but for some reason its still being strange. I reset my character 2 times when I walked through the start part and when I went through the end part my time showed up on the leaderboard. But when I speed ran the obby this morning with one of the homies our times didn’t show up. I just don’t understand what’s wrong with this script, it’s the only thing holding the game back! Please pay attention to the text at the very top of the script between the brackets. That’s what I was trying to tell you guys about!
--[[
@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!")
else
num = num * 1000
Store:SetAsync(plr.Name, num)
end
end
end)
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.