I have this local script where it locally shows the players cash value. The issue I’m getting for this is when I hover over the text, it shows the abbreviated version. However, when the value for the Cash updates, it reverts back to full form while the mouse is hovering over the text. I have tried using if statement but then it got confusing to the point that it feels wrong. So how do I make it when it updates while hovering over the text, it does not update back to the unabbreviated number, instead of updating it in the abbreviated version? Not a pro scripter but thanks for reaching out.
In conclusion, how to keep it in abbreviated form whilst the mouse hovering over the text?
Full Script:
local suffixes = {"K", "M", "B", "T", "q", "Q"}
function abbreviate(value)
local negative = (tonumber(value) or 0) < 0
if negative then
value = -(value)
end
if not (tonumber(value)) or tonumber(value) <= 999 then
return value
end
local str = value
for i = 1, #suffixes do
if tonumber(value) < 10 ^ (i * 3) then
str = math.floor(value / ((10 ^ ((i - 1) * 3)) / 100)) / 100 .. suffixes[i - 1]
break
end
end
if str and negative then str = "-"..str end
return str
end
local player = game.Players.LocalPlayer
script.Parent.Text = player.stats.Cash.Value
player.stats.Cash:GetPropertyChangedSignal("Value"):Connect(function()
script.Parent.Text = player.stats.Cash.Value
end)
script.Parent.MouseEnter:Connect(function()
local player = game.Players.LocalPlayer
script.Parent.Text = abbreviate(player.stats.Cash.Value)
end)
script.Parent.MouseLeave:Connect(function()
local player = game.Players.LocalPlayer
script.Parent.Text = player.stats.Cash.Value
end)
Tried using if statement:
script.Parent.MouseEnter:Connect(function()
if script.Parent.MouseEnter == true and player.stats.Cash:GetPropertyChangedSignal("Value") then
player.stats.Cash:GetPropertyChangedSignal("Value"):Connect(function()
script.Parent.Text = abbreviate(player.stats.Cash.Value)
end)
else
local player = game.Players.LocalPlayer
script.Parent.Text = abbreviate(player.stats.Cash.Value)
end
end)