Learn to read the errors for yourself, it has nothing to do with the code I sent you. Did you forgot to create the leaderstats
folder in your player instance? Also the loadstring() error isn’t related as well. Can you show me the explorer if the player has the leaderstats
folder or not?
I see, so you requested to the datastore from multiple scripts. I suggest moving them all to one script for easier handling because the limit is shared among all the scripts in a server. Here is the limit for datastore requests per server, not per datastore or per script, but for the entire server.
Get Async: 60 + (number of players x 10) requests per minute
Set Async: 60 + (number of players x 10) requests per minute
Get Sorted Async: 5 + (number of players x 2) requests per minute
Put all your get async, set async, and get sorted async functions into one script, then send me the result.
I see the issue. You are calling WaitForChild("leaderstats")
BEFORE you even created the leaderstats folder. The leaderstats folder was created in the updateLeaderstats
function, and the error of not finding leaderstats folder occurred in the loadDataStore
function. You called the loadDataStore
in the playerAdded event.
So add a line of code here
That way you create the leaderstats folder and everything BEFORE you call on it.
No, not yet… I don’t really know how to combine all the scripts into one
I understand. How many scripts in your game calls the datastore service? Maybe I can help you merge it all into one script if you show me all of them (this might take some time so bear with it)
Main Handler:
local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("myDataStore")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RebirthFunction = ReplicatedStorage:WaitForChild("Rebirth")
local RebirthFrame = game.StarterGui.ScreenGui.RebirthFrame.Cost
local MaxLevel = 5
local Abbreviations = {
"";
"K";
"M";
"B";
"T";
"Q";
"Qi";
"Sx";
"Sp";
"Oc";
"N";
"D";
"∞";
}
local function formatJumpHeight(jumpHeight)
for i = 1, #Abbreviations do
if jumpHeight < 10 ^ (i * 3) then
if Abbreviations[i] == "∞" then
return "∞"
else
return math.floor(jumpHeight / ((10 ^ ((i - 1) * 3)) / 100)) / 100 .. Abbreviations[i]
end
elseif tostring(jumpHeight) == "inf" then
return "∞"
end
end
end
-- Function to update player data in DataStore
local function updateDataStore(player)
local success, errorMessage = pcall(function()
local leaderstats = player:WaitForChild("leaderstats")
local jumpHeight = player.Character.Humanoid.JumpHeight
local winsValue = leaderstats:WaitForChild("Wins")
local rebirthsValue = leaderstats:WaitForChild("Rebirths")-- Assuming MaxLevel is a global variable
local rebirthframe = RebirthFrame
local data = {
JumpHeight = jumpHeight,
Wins = winsValue.Value,
Rebirths = rebirthsValue.Value,
Rebirth = tostring(rebirthframe)
}
myDataStore:SetAsync(player.UserId, data)
end)
if success then
print("Data is saved for " .. player.Name)
else
print("Error when saving data for " .. player.Name .. ": " .. errorMessage)
end
end
-- Function to load player data from DataStore
local function loadDataStore(player)
local success, errorMessage = pcall(function()
local data = myDataStore:GetAsync(player.UserId) or {}
local jumpHeight = data.JumpHeight
local wins = data.Wins
local rebirths = data.Rebirths
local rebirthcost = data.Rebirth
if jumpHeight ~= nil then
player.Character.Humanoid.JumpHeight = jumpHeight
end
if wins ~= nil then
local leaderstats = player:WaitForChild("leaderstats")
local winsValue = leaderstats:WaitForChild("Wins")
winsValue.Value = wins
end
if rebirths ~= nil then
local leaderstats = player:WaitForChild("leaderstats")
local rebirthsValue = leaderstats:WaitForChild("Rebirths")
rebirthsValue.Value = rebirths
end
if rebirthcost ~= nil then
rebirthcost = RebirthFrame
end
end)
if not success then
print("Error when loading data for " .. player.Name .. ": " .. errorMessage)
end
end
-- Function to update leaderstats with JumpPower and Wins value
local function updateLeaderstats(player)
-- Find or create the leaderstats folder in the player
local leaderstats = player:FindFirstChild("leaderstats")
if not leaderstats then
leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
end
-- Find or create the JumpHeight and Wins values in leaderstats
local jumpHeightValue = leaderstats:FindFirstChild("JumpHeight")
if not jumpHeightValue then
jumpHeightValue = Instance.new("StringValue")
jumpHeightValue.Name = "JumpHeight"
jumpHeightValue.Parent = leaderstats
end
local winsValue = leaderstats:FindFirstChild("Wins")
if not winsValue then
winsValue = Instance.new("IntValue")
winsValue.Name = "Wins"
winsValue.Parent = leaderstats
end
local RebirthsValue = leaderstats:FindFirstChild("Rebirths")
if not RebirthsValue then
RebirthsValue = Instance.new("IntValue")
RebirthsValue.Name = "Rebirths"
RebirthsValue.Parent = leaderstats
end
-- Update the JumpHeight and Wins values in leaderstats with abbreviated format
jumpHeightValue.Value = formatJumpHeight(player.Character.Humanoid.JumpHeight)
winsValue.Value = player:WaitForChild("leaderstats").Wins.Value
if RebirthsValue then
RebirthsValue.Value = player.leaderstats.Rebirths.Value
end
end
-- Connect PlayerAdded event
game.Players.PlayerAdded:Connect(function(plr)
-- Player Joined
-- Character Spawned
plr.CharacterAdded:Connect(function(char)
loadDataStore(plr)
end)
end)
RebirthFunction.OnServerInvoke = function(player)
if player.leaderstats.Wins.Value >= MaxLevel then
player.leaderstats.Rebirths.Value = player.leaderstats.Rebirths.Value + 1
player.leaderstats.Wins.Value = 0
player.Character.Humanoid.JumpHeight = 0
end
return false
end
-- Main loop
while true do
wait(1) -- Wait for 1 second
for _, player in pairs(game.Players:GetPlayers()) do
if player.Character then
-- Update leaderstats with new JumpHeight value
-- Update DataStore with new JumpHeight value if 5 seconds have passed since the last update
updateLeaderstats(player)
updateDataStore(player)
player.Character.Humanoid.JumpHeight += 1
-- Add the following line to increase JumpHeight by the value of Wins
player.Character.Humanoid.JumpHeight += player.leaderstats.Wins.Value
player.Character.Humanoid.JumpHeight += player.leaderstats.Rebirths.Value
end
end
end
Global JumpHeight Leaderboard:
local ds = game:GetService("DataStoreService")
local coinsODS = ds:GetOrderedDataStore("CoinsStats")
local players = game:GetService("Players")
local timeUntilReset = 15
local Abbreviations = {
"";
"K";
"M";
"B";
"T";
"Q";
"Qi";
"Sx";
"Sp";
"Oc";
"N";
"D";
"∞";
}
local function formatJumpHeight(jumpHeight)
for i = 1, #Abbreviations do
if jumpHeight < 10 ^ (i * 3) then
if Abbreviations[i] == "∞" then
return "∞"
else
return math.floor(jumpHeight / ((10 ^ ((i - 1) * 3)) / 100)) / 100 .. Abbreviations[i]
end
elseif tostring(jumpHeight) == "inf" then
return "∞"
end
end
end
while wait(1) do
timeUntilReset = timeUntilReset - 1
script.Parent.Parent.ResetTime.Text = "Resetting in " .. timeUntilReset .. " seconds..."
if timeUntilReset == 0 then
timeUntilReset = 10
for i, plr in pairs(game.Players:GetPlayers()) do
coinsODS:SetAsync(plr.UserId, plr.Character.Humanoid.JumpHeight)
end
for i, leaderboardRank in pairs(script.Parent:GetChildren()) do
if leaderboardRank.ClassName == "Frame" then
leaderboardRank:Destroy()
end
end
local success, errorMsg = pcall(function()
local data = coinsODS:GetSortedAsync(false, 50)
local coinsPage = data:GetCurrentPage()
for rankInLB, dataStored in ipairs(coinsPage) do
local name = game.Players:GetNameFromUserIdAsync(tonumber(dataStored.key))
local coins = dataStored.value
local template = script.Template:Clone()
template.Name = name .. "Leaderboard"
template.PlrName.Text = name
template.Rank.Text = "#" .. rankInLB
template.Coins.Text = formatJumpHeight(coins)
template.Parent = script.Parent
end
end)
if errorMsg then
print("Player : " .. players .. "Had an issue saving")
end
end
end
Global Wins Leaderboard:
local ds = game:GetService("DataStoreService")
local coinsODS = ds:GetOrderedDataStore("CoinsStats")
local players = game:GetService("Players")
local timeUntilReset = 10
local Abbreviations = {
"";
"K";
"M";
"B";
"T";
"Q";
"Qi";
"Sx";
"Sp";
"Oc";
"N";
"D";
"∞";
}
local function formatJumpHeight(jumpHeight)
for i = 1, #Abbreviations do
if jumpHeight < 10 ^ (i * 3) then
if Abbreviations[i] == "∞" then
return "∞"
else
return math.floor(jumpHeight / ((10 ^ ((i - 1) * 3)) / 100)) / 100 .. Abbreviations[i]
end
elseif tostring(jumpHeight) == "inf" then
return "∞"
end
end
end
while wait(1) do
timeUntilReset = timeUntilReset - 1
script.Parent.Parent.ResetTime.Text = "Resetting in " .. timeUntilReset .. " seconds..."
if timeUntilReset == 0 then
timeUntilReset = 10
for i, plr in pairs(game.Players:GetPlayers()) do
coinsODS:SetAsync(plr.UserId, plr.leaderstats.Wins.Value)
end
for i, leaderboardRank in pairs(script.Parent:GetChildren()) do
if leaderboardRank.ClassName == "Frame" then
leaderboardRank:Destroy()
end
end
local success, errorMsg = pcall(function()
local data = coinsODS:GetSortedAsync(false, 50)
local coinsPage = data:GetCurrentPage()
for rankInLB, dataStored in ipairs(coinsPage) do
local name = game.Players:GetNameFromUserIdAsync(tonumber(dataStored.key))
local coins = dataStored.value
local template = script.Template:Clone()
template.Name = name .. "Leaderboard"
template.PlrName.Text = name
template.Rank.Text = "#" .. rankInLB
template.Coins.Text = formatJumpHeight(coins)
template.Parent = script.Parent
end
end)
if errorMsg then
print("Player : " .. players .. "Had an issue saving")
end
end
end
Global Rebirth Leaderboard:
local ds = game:GetService("DataStoreService")
local coinsODS = ds:GetOrderedDataStore("CoinsStats")
local players = game:GetService("Players")
local timeUntilReset = 5
local Abbreviations = {
"";
"K";
"M";
"B";
"T";
"Q";
"Qi";
"Sx";
"Sp";
"Oc";
"N";
"D";
"∞";
}
local function formatJumpHeight(jumpHeight)
for i = 1, #Abbreviations do
if jumpHeight < 10 ^ (i * 3) then
if Abbreviations[i] == "∞" then
return "∞"
else
return math.floor(jumpHeight / ((10 ^ ((i - 1) * 3)) / 100)) / 100 .. Abbreviations[i]
end
elseif tostring(jumpHeight) == "inf" then
return "∞"
end
end
end
while wait(1) do
timeUntilReset = timeUntilReset - 1
script.Parent.Parent.ResetTime.Text = "Resetting in " .. timeUntilReset .. " seconds..."
if timeUntilReset == 0 then
timeUntilReset = 10
for i, plr in pairs(game.Players:GetPlayers()) do
coinsODS:SetAsync(plr.UserId, plr.leaderstats.Rebirths.Value)
end
for i, leaderboardRank in pairs(script.Parent:GetChildren()) do
if leaderboardRank.ClassName == "Frame" then
leaderboardRank:Destroy()
end
end
local success, errorMsg = pcall(function()
local data = coinsODS:GetSortedAsync(false, 50)
local coinsPage = data:GetCurrentPage()
for rankInLB, dataStored in ipairs(coinsPage) do
local name = game.Players:GetNameFromUserIdAsync(tonumber(dataStored.key))
local coins = dataStored.value
local template = script.Template:Clone()
template.Name = name .. "Leaderboard"
template.PlrName.Text = name
template.Rank.Text = "#" .. rankInLB
template.Coins.Text = formatJumpHeight(coins)
template.Parent = script.Parent
end
end)
if errorMsg then
print("Player : " .. players .. "Had an issue saving")
end
end
end
```I am sorry that this is really long
Here are all of my scripts I apologize because it is pretty long
As a side note, you should really figure out what script is doing this and get rid of it. This looks like malicious code:
It is just animation spoofer, I don’t think it is malicious.
You can go to the toolbox on the plugins tab and search animation spoofer, then tell me if it looks malicious to you or not.
I’ll combine them when I am free (because I have school and highschool exam is coming up)
Also make sure that those are all the scripts that uses datastore, or else I will be wasting my time I’ll probably get back to you in less than 24 hours with the new code
Edit: Because there are lots of datastore requests I’ll just make a new empty game and test it out there.
For the three leaderboards, it seems like you put the script under the gui. Do you mind giving me the path of each of the leaderboards / screenshot of the explorer? Because to put it all in one script you can’t use script.Parent
Hi, I am not sure if you are still here and its been a while, but I made some changes.
local function updateDataStore(player)
local success, errorMessage = pcall(function()
local leaderstats = player:WaitForChild("leaderstats")
local jumpHeight = player.Character.Humanoid.JumpHeight
local winsValue = leaderstats:WaitForChild("Wins")
local rebirthsValue = leaderstats:WaitForChild("Rebirths")
local rebirthframe = player.PlayerGui.RebirthGUI.RebirthFrame.Cost.Text
local data = {
JumpHeight = jumpHeight,
Wins = winsValue.Value,
Rebirths = rebirthsValue.Value,
Rebirth = rebirthframe
}
myDataStore:SetAsync(player.UserId, data)
end)
if success then
print("Data is saved for " .. player.Name)
else
print("Error when saving data for " .. player.Name .. ": " .. errorMessage)
end
end
local function loadDataStore(player)
local success, errorMessage = pcall(function()
local data = myDataStore:GetAsync(player.UserId) or {}
local jumpHeight = data.JumpHeight
local wins = data.Wins
local rebirths = data.Rebirths
local rebirthcost = data.Rebirth
if jumpHeight ~= nil then
player.Character.Humanoid.JumpHeight = jumpHeight
end
if wins ~= nil then
local leaderstats = player:WaitForChild("leaderstats")
local winsValue = leaderstats:WaitForChild("Wins")
winsValue.Value = wins
end
if rebirths ~= nil then
local leaderstats = player:WaitForChild("leaderstats")
local rebirthsValue = leaderstats:WaitForChild("Rebirths")
rebirthsValue.Value = rebirths
end
if rebirthcost ~= nil then
rebirthcost = rebirthcost
end
end)
if not success then
print("Error when loading data for " .. player.Name .. ": " .. errorMessage)
end
end
game.Players.PlayerRemoving:Connect(function(plr)
updateDataStore(plr)
end)
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
loadDataStore(player)
end)
end)
The issue is it loads but never updates. Example: If you had 100 JumpHeight and played for a bit like 5-10 minutes, and you leave and rejoin. You would still have 100 JumpHeight
I get it, it’s because you are the last player to leave the server so it isn’t called. Try add this:
game:BindToClose(function()
for i, v in pairs(game.Players:GetPlayers()) do
updateDataStore(v)
end
end)
also replace the loading code with this:
game.Players.PlayerAdded:Connect(function(player)
loadDataStore(player)
end)
That should fix the SetAsync
too many datastore request warning, but it will not fix the GetSortedAsync
too many datastore request warning. Can I see the code that uses GetSortedAsync
? I know how to fix it with some simple math.