Hello! I have a script that abbreviates the number! However, it returns as zero why? I’ve added some comments that I’ve printed. Please help!
local BallFrame = script.Parent
local RS = game:GetService("ReplicatedStorage")
local plr = game.Players.LocalPlayer
local TS = game:GetService("TweenService")
local info = TweenInfo.new(.1, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)
local GrantMP = RS:WaitForChild("GrantMP") -- Event
local Cost = RS:WaitForChild("Cost") -- Event
local BuyUpgrade = BallFrame:GetChildren()
local Divisible = 1.3 -- Divible by Offset
local Upg = 1.5
local Abbreviations = {
"";
"K";
"M";
"B";
"T";
"q";
"Q";
"s";
"S";
"o";
"n";
"d";
"U";
"D";
"Tr";
"Qt";
"Qd";
"Sd";
"St";
"Oct";
"Nod";
"Vg";
"Uvg";
"Dvg";
"e70";
"e71";
"Tvg";
"e73";
"e74";
"Qavg";
"e76";
"e77";
"Qivg";
"e79";
"e80";
"Sxvg";
"e82";
"e83";
"Spvg";
"e85";
"e86";
"ocvg"
}
local function Number_Abbreviations(Number)
for i=1, #Abbreviations do
if Number < 10 ^ (i * 3) then
if Abbreviations[i] == "∞" then
return "∞"
else
return math.floor(Number / ((10 ^ ((i-1) * 3)) / 100)) / (100) .. Abbreviations[i]
end
elseif tostring(Number) == "inf" then
return "∞"
end
end
end
for i, Button in pairs(BuyUpgrade) do
if Button:IsA("TextButton") then
local ButtonX = Button.Size.X
local ButtonY = Button.Size.Y
Button.MouseButton1Down:Connect(function()
if plr.leaderstats.Balloras.Value >= Button.Cost.Value then
Cost:FireServer(Button.Cost.Value)
GrantMP:FireServer(Button.RewardMP.Value)
local Calculation = math.round(plr.MP.Value * Upg)
Button.Cost.Value *= Calculation -- Returns Zero and Button.Cost.Value is 10
Button.Text = Button.Upgrade.Value.." "..tostring(Number_Abbreviations(Button.Cost.Value)).."$"
end
end)
Button.MouseEnter:Connect(function()
TS:Create(Button, info, {Size = UDim2.new(Button.Size.X.Scale, Button.Size.X.Offset/Divisible, Button.Size.Y.Scale, Button.Size.Y.Offset/Divisible)}):Play()
end)
Button.MouseLeave:Connect(function()
TS:Create(Button, info, {Size = UDim2.new(Button.Size.X.Scale, ButtonX.Offset, Button.Size.Y.Scale, ButtonY.Offset)}):Play()
end)
while true do
local Calculation = math.round(plr.MP.Value * Upg)
print("This is "..Calculation) -- Returns the Calculations (Works)
Button.Cost.Value *= Calculation -- Button.Cost.Value is 10
print(Button.Cost.Value) -- Return also zero but why?
Button.Text = Button.Upgrade.Value.." "..tostring(Number_Abbreviations(Button.Cost.Value)).."$" -- Returns value as zero?
task.wait(1)
end
end
end