Hello, I am trying to make a crown system so when a player has the most amount of money, the player will get a crown on top of his head and It will follow him, It works but If you go a bit faster It slows down, Is there any way to always be on the player head, without some delay? any help is appreciated!
wait(10)
function abbreviateNumber(n)
if n > 1000 and n < 1000000 then
local round = math.floor(n / 1000)
local round2 = n - round*1000
return round .. "." .. math.floor(round2/100) .. "K+"
elseif n > 1000000 and n < 1000000000 then
local round = math.floor(n / 1000000)
local round2 = n - round*1000000
return round .. "." .. math.floor(round2/100000) .. "M+"
elseif n > 1000000000 and n < 1000000000000 then
local round = math.floor(n / 1000000000)
local round2 = n - round*1000000000
return round .. "." .. math.floor(round2/100000000) .. "B+"
elseif n > 1000000000000 then
local round = math.floor(n / 1000000000000)
local round2 = n - round*1000000000000
return round .. "." .. math.floor(round2/100000000000) .. "T+"
else
return n .. ""
end
end
function CrownSearch()
local RichPlayer
local LastRich = 0
local Player
for i,v in pairs(game.ServerStorage.PlayerMoney:GetChildren()) do
if v.ClassName == "NumberValue" then
if v.Value > LastRich then
RichPlayer = v.Name
Player = game.Players:FindFirstChild(RichPlayer)
LastRich = v.Value
end
end
end
if RichPlayer ~= nil and Player~= nil then
local CashAT = abbreviateNumber(LastRich)
workspace.Cast.Crown.Value = ("π "..RichPlayer.." IS THE RICHEST WITH $"..CashAT.." π")
if Player.Character:FindFirstChild("Head") ~= nil then
if workspace:FindFirstChild("RichestMesh") then
if workspace.RichestMesh:FindFirstChild("Crown") then
workspace.RichestMesh.Crown.BodyPosition.Position = Player.Character.Head.Position + Vector3.new(0,3.20,0)
end
end
end
else
workspace.Cast.Crown.Value = ("")
end
end
while wait() do
if #game.Players:GetChildren() > 0 then
CrownSearch()
end
end
It has a delay is because each line of code is a step, and those steps arenβt noticeable normally but in this case this is an inefficient way to position something with checks going on that have a lot of lines.
First create a new weld, and weld it to the head then crown on creation. Next, send an image of what it looks like in-game without the loop, and I will tell you how to position it correctly
Is It possible to create everything via a script, something like this one?
function abbreviateNumber(n)
if n > 1000 and n < 1000000 then
local round = math.floor(n / 1000)
local round2 = n - round * 1000
return round .. "." .. math.floor(round2 / 100) .. "K+"
elseif n > 1000000 and n < 1000000000 then
local round = math.floor(n / 1000000)
local round2 = n - round * 1000000
return round .. "." .. math.floor(round2 / 100000) .. "M+"
elseif n > 1000000000 and n < 1000000000000 then
local round = math.floor(n / 1000000000)
local round2 = n - round * 1000000000
return round .. "." .. math.floor(round2 / 100000000) .. "B+"
elseif n > 1000000000000 then
local round = math.floor(n / 1000000000000)
local round2 = n - round * 1000000000000
return round .. "." .. math.floor(round2 / 100000000000) .. "T+"
else
return n .. ""
end
end
function CrownSearch()
local RichPlayer
local LastRich = 0
local Player
for i, v in pairs(game.ServerStorage.PlayerMoney:GetChildren()) do
if v.ClassName == "NumberValue" and v.Value > LastRich then
RichPlayer = v.Name
Player = game.Players:FindFirstChild(RichPlayer)
LastRich = v.Value
end
end
if RichPlayer and Player then
local CashAT = abbreviateNumber(LastRich)
workspace.Cast.Crown.Value = ("π " .. RichPlayer .. " IS THE RICHEST WITH $" .. CashAT .. " π")
if Player.Character and Player.Character:FindFirstChild("Head") then
local head = Player.Character.Head
local richestMesh = workspace:FindFirstChild("RichestMesh")
if richestMesh and richestMesh:FindFirstChild("Crown") then
local crown = richestMesh.Crown
if not crown:FindFirstChild("Weld") then
local weld = Instance.new("Weld")
weld.Part0 = crown
weld.Part1 = head
weld.C0 = crown.CFrame:inverse()
weld.C1 = head.CFrame:inverse()
weld.Parent = crown
else
local weld = crown.Weld
weld.C0 = crown.CFrame:inverse()
weld.C1 = head.CFrame:inverse()
end
crown.BodyPosition.Position = head.Position + Vector3.new(0, 3.20, 0)
end
end
else
workspace.Cast.Crown.Value = ("")
end
end
while wait() do
if #game.Players:GetChildren() > 0 then
CrownSearch()
end
end
function abbreviateNumber(n)
if n > 1000 and n < 1000000 then
local round = math.floor(n / 1000)
local round2 = n - round * 1000
return round .. "." .. math.floor(round2 / 100) .. "K+"
elseif n > 1000000 and n < 1000000000 then
local round = math.floor(n / 1000000)
local round2 = n - round * 1000000
return round .. "." .. math.floor(round2 / 100000) .. "M+"
elseif n > 1000000000 and n < 1000000000000 then
local round = math.floor(n / 1000000000)
local round2 = n - round * 1000000000
return round .. "." .. math.floor(round2 / 100000000) .. "B+"
elseif n > 1000000000000 then
local round = math.floor(n / 1000000000000)
local round2 = n - round * 1000000000000
return round .. "." .. math.floor(round2 / 100000000000) .. "T+"
else
return n .. ""
end
end
function CrownSearch()
local RichPlayer
local LastRich = 0
local Player
for i, v in pairs(game.ServerStorage.PlayerMoney:GetChildren()) do
if v.ClassName == "NumberValue" and v.Value > LastRich then
RichPlayer = v.Name
Player = game.Players:FindFirstChild(RichPlayer)
LastRich = v.Value
end
end
if RichPlayer and Player then
local CashAT = abbreviateNumber(LastRich)
workspace.Cast.Crown.Value = ("π " .. RichPlayer .. " IS THE RICHEST WITH $" .. CashAT .. " π")
if Player.Character and Player.Character:FindFirstChild("Head") then
local head = Player.Character.Head
local richestMesh = workspace:FindFirstChild("RichestMesh")
if richestMesh and richestMesh:FindFirstChild("Crown") then
local crown = richestMesh.Crown
local head = head
local crown = crown
local Weld = Instance.new("Weld")
Weld.Part0 = head
Weld.Part1 = crown
Weld.Parent = head
Weld.C0 = CFrame.new(0, 3, 0)
--crown.BodyPosition.Position = head.Position + Vector3.new(0, 3.0, 0)
end
end
else
workspace.Cast.Crown.Value = ("")
end
end
while wait() do
if #game.Players:GetChildren() > 0 then
CrownSearch()
end
end