Hey so i made a script for this rig thats supposed to show the most wins in the server but its not working. anyone know why?
local Players = game:GetService("Players")
local Workspace = game:GetService("Workspace")
local statueName = "WinsStatue"
local statName = "Wins"
local updateTime = 10
local function getTopPlayer()
local allPlayers = Players:GetPlayers()
local topPlayer = nil
local highestWins = -1
for _, player in ipairs(allPlayers) do
local leaderstats = player:FindFirstChild("leaderstats")
if leaderstats then
local winsStat = leaderstats:FindFirstChild(statName)
if winsStat and winsStat.Value > highestWins then
highestWins = winsStat.Value
topPlayer = player
end
end
end
return topPlayer
end
local function updateStatue()
local statue = Workspace:FindFirstChild(statName)
if not statue then return end
local humanoid = statue:FindFirstChildOfClass("Humanoid")
if not humanoid then return end
local topPlayer = getTopPlayer()
if topPlayer then
local success, description = pcall(function()
return Players:GetHumanoidDescriptionFromUserIdAsync(topPlayer.UserId)
end)
if success and description then
humanoid:ApplyDescriptionAsync(description)
statue.Name = topPlayer.DisplayName .. " (#1 Winner)"
end
else
statue.Name = "No Top Player Yet"
end
end
task.spawn(function()
while true do
updateStatue()
task.wait(updateTime)
end
end)
In function updateStatue and in the first line of the function:
local statue = Workspace:FindFirstChild(statName)
You’re using statName, which, according to the script, is for the leaderstat name “Wins”; you may have made a typo here. Instead, use statueName (which refers to the string “WinsStatue” in the script), which changes that line of code to look like this instead:
local statue = Workspace:FindFirstChild(statueName) -- statueName, not statName
You may also want to update the statueName variable too upon updating statue.Name at the very end of the updateStatue function as well
Everything else other than that line of code seems fine to me
Did you also add statueName = statue.Name at the end of updateStatue? That has to be included in too since we’re modifying a value (statue.Name) that statueName tries to reference in the first line of updateStatue
This is how the code should look like:
local Players = game:GetService("Players")
local Workspace = game:GetService("Workspace")
local statueName = "WinsStatue"
local statName = "Wins"
local updateTime = 10
local function getTopPlayer()
local allPlayers = Players:GetPlayers()
local topPlayer = nil
local highestWins = -1
for _, player in ipairs(allPlayers) do
local leaderstats = player:FindFirstChild("leaderstats")
if leaderstats then
local winsStat = leaderstats:FindFirstChild(statName)
if winsStat and winsStat.Value > highestWins then
highestWins = winsStat.Value
topPlayer = player
end
end
end
return topPlayer
end
local function updateStatue()
local statue = Workspace:FindFirstChild(statueName)
if not statue then return end
local humanoid = statue:FindFirstChildOfClass("Humanoid")
if not humanoid then return end
local topPlayer = getTopPlayer()
if topPlayer then
local success, description = pcall(function()
return Players:GetHumanoidDescriptionFromUserIdAsync(topPlayer.UserId)
end)
if success and description then
humanoid:ApplyDescriptionAsync(description)
statue.Name = topPlayer.DisplayName .. " (#1 Winner)"
end
else
statue.Name = "No Top Player Yet"
end
statueName = statue.Name -- added
end
task.spawn(function()
while true do
updateStatue()
task.wait(updateTime)
end
end)
Then we’ll have to query all of the BodyScale NumberValues parented to our Humanoid of our WinsStatue; in the code below, we use :QueryDescendants() for this, and we pass in a ClassName string (what type of descendants from our Humanoid do we want tor retrieve, in this case, we want NumberValues, since the BodyScale values in our Humanoid should be stored as NumberValues)
Then, we would have to loop though our body_scales table and multiply the NumberValue’s Value by a constant DESIRED_STATUE_SCALE, which I’ve declared as 4 in this code (change this to the desired scale multiplier for your WinsStatue rig)
(the NumberValue v in question is assumed to be our BodyScale within Humanoid)
Full code with the rig size patches for reference:
local Players = game:GetService("Players")
local Workspace = game:GetService("Workspace")
local statueName = "WinsStatue"
local statName = "Wins"
local updateTime = 10
const DESIRED_STATUE_SCALE: number = 4 -- added
local function getTopPlayer()
local allPlayers = Players:GetPlayers()
local topPlayer = nil
local highestWins = -1
for _, player in ipairs(allPlayers) do
local leaderstats = player:FindFirstChild("leaderstats")
if leaderstats then
local winsStat = leaderstats:FindFirstChild(statName)
if winsStat and winsStat.Value > highestWins then
highestWins = winsStat.Value
topPlayer = player
end
end
end
return topPlayer
end
local function updateStatue()
local statue = Workspace:FindFirstChild(statueName)
if not statue then return end
local humanoid = statue:FindFirstChildOfClass("Humanoid")
if not humanoid then return end
local topPlayer = getTopPlayer()
if topPlayer then
local success, description = pcall(function()
return Players:GetHumanoidDescriptionFromUserIdAsync(topPlayer.UserId)
end)
if success and description then
humanoid:ApplyDescriptionAsync(description)
local body_scales = humanoid:QueryDescendants("NumberValue") -- added
for _, v: NumberValue in body_scales do -- added
v.Value *= DESIRED_STATUE_SCALE -- added
end -- added
statue.Name = topPlayer.DisplayName .. " (#1 Winner)"
end
else
statue.Name = "No Top Player Yet"
end
statueName = statue.Name
end
task.spawn(function()
while true do
updateStatue()
task.wait(updateTime)
end
end)
Also: in case you may be interested into :QueryDescendants() (which could come in handy in situations like this), here’s a link to the docs article about it: Instance | Documentation - Roblox Creator Hub