local ODS = DSS:GetOrderedDataStore("Cash")
local stat = script.Parent.Stats
local Template = game:GetService("ServerStorage"):WaitForChild("Template")
local cooldown = 10
local function updateBoard()
local data = ODS:GetSortedAsync(false, 10)
local page = data:GetCurrentPage()
for i, v in ipairs(page) do
local name = game:GetService("Players"):GetNameFromUserIdAsync(v.key)
local cash = v.value
local rank = i
local onBoard = false
local notation = require(game.ReplicatedStorage.SNotation)
for i, v in pairs(stat:GetChildren()) do
if v:IsA("UIListLayout") then continue end
if v.Name == name then
onBoard = true
end
end
if cash and onBoard then
local temp = Template:Clone()
temp.Name = name
temp.Username.Text = name
temp.Rank.Text = rank
temp.Value.Text = notation.short(cash)
temp.Parent = stat
temp.LayoutOrder = i
temp.Position = UDim2.new(0, 0, 0, (i-1)*100)
if rank == 1 then
temp.Rank.TextColor3 = Color3.fromRGB(255, 255, 55)
elseif rank == 2 then
temp.Rank.TextColor3 = Color3.fromRGB(180, 180, 180)
elseif rank == 3 then
temp.Rank.TextColor3 = Color3.fromRGB(170, 103, 37)
end
end
end
end
while true do
for i, v in ipairs(game:GetService("Players"):GetPlayers()) do
print("User ID:", v.UserId)
print("Cash value:", v.Stats.Cash.Value)
ODS:SetAsync(v.UserId, v.Stats.Cash.Value)
end
for i, v in pairs(stat:GetChildren()) do
if v:IsA("UIListLayout") then continue end
v:Destroy()
end
updateBoard()
task.wait(cooldown)
end```
#trouble with leaderboard script
118 messages · Page 1 of 1 (latest)
** You are now Level 5! **
i also tried printing v.key and it printed me a -2
hello noah!
you want leaderboard for what?
For my stats called Cash
alroght
alroght
i*
bruh
one sec
local Players = game:GetService("Players")
function onPlayerAdded(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local cash = Instance.new("IntValue")
cash.Name = "Cash"
cash.Value = 0
cash.Parent = leaderstats
end
function onPlayerChatted(msg, player)
if string.lower(msg) == "!addcash" then
local leaderstats = player:FindFirstChild("leaderstats")
if leaderstats then
local cash = leaderstats:FindFirstChild("Cash")
if cash then
cash.Value = cash.Value + 50 -- change 50 to whatever value you want
end
end
end
end
game.Players.PlayerAdded:Connect(onPlayerAdded)
Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(msg)
onPlayerChatted(msg, player)
end)
end)
da code creates a leaderboard for the player's cash when they join th game and listens for chat messages to add cash to their account The !addcash command adds 50 cash to the player's account you can change this value to any amount you prefer
To use this script, create a Script object in Roblox Studio and copy and paste this code into it.
u want this true
I already have that
alr
I have like the stats script already aswell for datastore
lemme search for another
local Players = game:GetService("Players")
local cashLeaderboard = Instance.new("Folder")
cashLeaderboard.Name = "leaderstats"
cashLeaderboard.Parent = game
local cash = Instance.new("IntValue")
cash.Name = "Cash"
cash.Value = 0
cash.Parent = cashLeaderboard
function onCashCollected(player)
cash.Value = cash.Value + 1
cashLeaderboard:GetPropertyChangedSignal("Name"):Connect(function()
for _, plr in ipairs(Players:GetPlayers()) do
local leaderstats = plr:FindFirstChild("leaderstats")
if leaderstats then
leaderstats:FindFirstChild("Cash").Value = cash.Value
end
end
end)
end
game.ReplicatedStorage.CashCollected.OnServerEvent:Connect(onCashCollected)
thi code creates a leaderboard for the player s cash and updates it whenever a player collects cash using a RemoteEvent named CashCollected you can replace this event with your own custom event
To use this script create a Script object in Roblox Studio and copy and paste this code into it You may also need to add additional logic to handle ties and prevent cheating if needed
about
what does that even do that function part
wait ive changed my script yesterday ill copy n paste it and show u the error now
The onCashCollected() function in the cash leaderboard script I provided is called whenever a player collects cash in the game using the CashCollected event The purpose of this function is to update the Cash value in the cashLeaderboard folder by incrementing it by 1 for each cash collected
The function also has a signal listener for changes to the Name property of the cashLeaderboard folder this is necessary because the leaderboard s Name property must change to trigger a leaderboard update for all players
local DSS = game:GetService("DataStoreService")
local ODS = DSS:GetOrderedDataStore("Cash")
local stat = script.Parent.Stats
local Template = game:GetService("ServerStorage"):WaitForChild("Template")
local Players = game:GetService("Players")
local COLORS = {
Default = Color3.fromRGB(38, 50, 56),
Gold = Color3.fromRGB(255, 215, 0),
Silver = Color3.fromRGB(192, 192, 192),
Bronze = Color3.fromRGB(205, 127, 50)
}
local cooldown = 10
local function updateBoard()
local data = ODS:GetSortedAsync(false, 10, 1, math.huge)
local page = data:GetCurrentPage()
for i, v in ipairs(page) do
local name = "Not Available"
local cash = v.value
local rank = i
local color = COLORS.Default
local notation = require(game.ReplicatedStorage.SNotation)
local success, err = pcall(function()
name = Players:GetNameFromUserIdAsync(v.key)
end)
if rank == 1 then
color = Color3.fromRGB(255, 255, 55)
elseif rank == 2 then
color = Color3.fromRGB(180, 180, 180)
elseif rank == 3 then
color = Color3.fromRGB(170, 103, 37)
local temp = Template:Clone()
temp.Name = name
temp.LayoutOrder = rank
temp.Rank.TextColor3 = color
temp.Rank.Text = rank
temp.Username.Text = name
temp.Value.Text = notation.short(cash)
temp.Parent = stat
if rank == 1 then
temp.Rank.TextColor3 = Color3.fromRGB(255, 255, 55)
elseif rank == 2 then
temp.Rank.TextColor3 = Color3.fromRGB(180, 180, 180)
elseif rank == 3 then
temp.Rank.TextColor3 = Color3.fromRGB(170, 103, 37)
end
end
end
end
while true do
for _, player in pairs(Players:GetPlayers()) do
local leaderstats = player:FindFirstChild("Stats")
if not leaderstats then
warn("Couldn't find leaderstats!")
break
end
local statsValue = leaderstats:FindFirstChild("Cash")
if not statsValue then
warn("Couldn't find " .. "Cash" .. " in leaderstats!")
break
end
pcall(function()
ODS:UpdateAsync(player.UserId, function()
return tonumber(statsValue.Value)
end)
end)
end
for _, item in pairs(stat:GetChildren()) do
if item:IsA("Frame") then
item:Destroy()
end
end
updateBoard()
wait()
wait(cooldown)
end
this is what i got right now
where did u get it from
i made it myself idk
okay
urs isnt working?
ok
thx
local Players = game:GetService("Players")
local cashLeaderboard = Instance.new("Folder")
cashLeaderboard.Name = "leaderstats"
cashLeaderboard.Parent = game
local cash = Instance.new("IntValue")
cash.Name = "Cash"
cash.Value = 0
cash.Parent = cashLeaderboard
function onCashCollected(player)
cash.Value = cash.Value + 1
cashLeaderboard:GetPropertyChangedSignal("Name"):Connect(function()
for _, plr in ipairs(Players:GetPlayers()) do
local leaderstats = plr:FindFirstChild("leaderstats")
if leaderstats then
leaderstats:FindFirstChild("Cash").Value = cash.Value
end
end
end)
end
game.ReplicatedStorage.CashCollected.OnServerEvent:Connect(onCashCollected)
i fixed urs should be
while true do
for i, player in pairs(Players:GetPlayers()) do
local leaderstats = player:FindFirstChild("Stats")
if not leaderstats then
warn("Couldn't find leaderstats!")
break
end
local statsValue = leaderstats:FindFirstChild("Cash")
if not statsValue then
warn("Couldn't find " .. "Cash" .. " in leaderstats!")
break
end
pcall(function()
ODS:UpdateAsync(player.UserId, function()
return tonumber(statsValue.Value)
end)
end)
end
for i, item in pairs(stat:GetChildren()) do
if item:IsA("Frame") then
item:Destroy()
end
end
updateBoard()
wait()
wait(cooldown)
end
thats mine
thats urs
but i fixed it
oh instead of the i i had _
thats not for a global leaderboardis it
i need help with a global one
thats what it looks like it doesnt say any errors
i used this one before i treid making myself one but it caps at 9.2Qn and it doesnt go any higher\
hi
yea its really confusing
or no
ye
where do i put it
maybe its the budget
do i just put it over the script i use
yea how do i change that
im back
yo
from the script
yoo
what script did u use
urs?
yea
ok one sec
ive changed mine again
local DSS = game:GetService("DataStoreService")
local ODS = DSS:GetOrderedDataStore("Cash")
local stat = script.Parent.Stats
local Template = game:GetService("ServerStorage"):WaitForChild("Template")
local cooldown = 10
local function updateBoard()
local data = ODS:GetSortedAsync(false, 10)
local page = data:GetCurrentPage()
for i, v in ipairs(page) do
local name = game:GetService("Players"):GetNameFromUserIdAsync(v.key)
local cash = v.value
local rank = i
local onBoard = false
local notation = require(game.ReplicatedStorage.SNotation)
for i, v in pairs(stat:GetChildren()) do
if v:IsA("UIListLayout") then continue end
if v.Name == name then
onBoard = true
end
end
if cash and not onBoard then
local temp = Template:Clone()
temp.Name = name
temp.LayoutOrder = rank
temp.Username.Text = name
temp.Rank.Text = rank
temp.Value.Text = notation.short(cash)
temp.Parent = stat
if rank == 1 then
temp.Rank.TextColor3 = Color3.fromRGB(255, 255, 55)
elseif rank == 2 then
temp.Rank.TextColor3 = Color3.fromRGB(180, 180, 180)
elseif rank == 3 then
temp.Rank.TextColor3 = Color3.fromRGB(170, 103, 37)
else
temp.Rank.TextColor3 = temp.Rank.TextColor3
end
end
end
end
while true do
for i, v in ipairs(game:GetService("Players"):GetPlayers()) do
ODS:SetAsync(v.UserId, v.Stats.Cash.Value)
end
for i, v in pairs(stat:GetChildren()) do
if v:IsA("UIListLayout") then continue end
v:Destroy()
end
updateBoard()
task.wait(cooldown)
end
alr
put the script
in serverscriptservice
put mine
while true do
for i, player in pairs(Players:GetPlayers()) do
local leaderstats = player:FindFirstChild("Stats")
if not leaderstats then
warn("Couldn't find leaderstats!")
break
end
local statsValue = leaderstats:FindFirstChild("Cash")
if not statsValue then
warn("Couldn't find " .. "Cash" .. " in leaderstats!")
break
end
pcall(function()
ODS:UpdateAsync(player.UserId, function()
return tonumber(statsValue.Value)
end)
end)
end
for i, item in pairs(stat:GetChildren()) do
if item:IsA("Frame") then
item:Destroy()
end
end
updateBoard()
wait()
wait(cooldown)
end
try this
put on ServerScriptService
okay but wait
what
so it kinda works now but it says 502: API Services rejected request with error. HTTP 400 (Bad Request)
also the order isnt right
local Players = game:GetService("Players")
local cashLeaderboard = Instance.new("Folder")
cashLeaderboard.Name = "leaderstats"
cashLeaderboard.Parent = game
local cash = Instance.new("IntValue")
cash.Name = "Cash"
cash.Value = 0
cash.Parent = cashLeaderboard
function onCashCollected(player)
cash.Value = cash.Value + 1
cashLeaderboard:GetPropertyChangedSignal("Name"):Connect(function()
for _, plr in ipairs(Players:GetPlayers()) do
local leaderstats = plr:FindFirstChild("leaderstats")
if leaderstats then
leaderstats:FindFirstChild("Cash").Value = cash.Value
end
end
end)
end
game.ReplicatedStorage.CashCollected.OnServerEvent:Connect(onCashCollected)
try this
.
..
did it work
local Data = game:GetService("DataStoreService"):GetDataStore("DataMonkey")
local Players = game:GetService("Players")
game.Players.PlayerAdded:Connect(function(Player)
local Stats = Instance.new("Folder", Player)
Stats.Name = "Stats"
local Cash = Instance.new("NumberValue", Stats)
Cash.Name = "Cash"
Cash.Value = 0
local Multiplier = Instance.new("NumberValue", Stats)
Multiplier.Name = "Multiplier"
Multiplier.Value = 0
local Rebirth = Instance.new("NumberValue", Stats)
Rebirth.Name = "Rebirth"
Rebirth.Value = 0
local Ant = Instance.new("NumberValue", Stats)
Ant.Name = "Ant"
Ant.Value = 0
function onCashCollected(player)
Cash.Value = Cash.Value + 1
Stats:GetPropertyChangedSignal("Name"):Connect(function()
for _, plr in ipairs(Players:GetPlayers()) do
local leaderstats = plr:FindFirstChild("Stats")
if leaderstats then
leaderstats:FindFirstChild("Cash").Value = Cash.Value
while true do
local Result = 1
if Player.Stats.Multiplier.Value >= 1 then
Result = Result*2*Player.Stats.Multiplier.Value
end
if Player.Stats.Rebirth.Value >= 1 then
Result = Result*2*Player.Stats.Rebirth.Value
end
if Player.Stats.Ant.Value >= 1 then
Result = Result*1.5*Player.Stats.Ant.Value
end
Cash.Value = Cash.Value + Result
wait(0.1)
end
end
end
end)
end
end)
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(onCashCollected)
this is what i got now
the stats script
but it says Attempt to connect failed: Passed value is not a function
uhh
wait
found a solution
in google
The error message "Attempt to connect failed: Passed value is not a function" typically means that you are trying to connect an event listener to an event, but the second parameter you are passing is not a function.
In the context of the Roblox API, this often happens when the Connect() function is called with an improperly-formatted function parameter or a non-function value.
Here are a few potential solutions to this error:
- Check that the second parameter you are passing to the
Connect()function is a function. You can do this by using thetype()function to verify that the parameter is a function:
print(type(myFunction)) -- should output "function"
- If the variable you are passing to the
Connect()function is a string that represents the name of a function, make sure that the function actually exists in the script:
function myFunction()
print("Hello, world!")
end
local functionName = "myFunction"
-- This should work because "myFunction" exists as a function in the script
someEvent:Connect(functionName)
- Make sure that the function parameter you are passing to
Connect()is properly formatted. For example, if you are trying to use an inline function, make sure that it is enclosed in parentheses and that the function body is enclosed in curly braces:
someEvent:Connect(function()
-- do something here
end)
If none of these solutions work, please let me know and provide more context surrounding the error message, and I will do my best to further assist you.
i got this solution
try it
found in on google chrome
alr
u didnt understand it?