Hello, I’ve coded a function in the game with the help of someone in the forum that will calculate the cost of an upgrade and then display the next benefits for each upgrade… but for some reason instead of displaying ‘1.85,1.90,1.95’ etc … its displaying ‘1.85000000000000000001’ and i honestly have no idea what its causing this issue, here is a screenshot of the in-game GUI…
Here’s the GUI code…
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local player = Players.LocalPlayer
local MultiplierFolder = player:WaitForChild("MultiplierFolder")
local Multiplier1 = MultiplierFolder:WaitForChild("Multiplier1")
local ScreenGui = script.Parent
local MainFrame = ScreenGui:WaitForChild("MainFrame")
local NextPrice = MainFrame:WaitForChild("NextPrice")
local CurrentMulti = MainFrame:WaitForChild("CurrentMulti")
local NextMulti = MainFrame:WaitForChild("NextMulti")
local CloseButton = MainFrame:WaitForChild("CloseButton")
local UpgradeButton = MainFrame:WaitForChild("UpgradeButton")
local Remotes = ReplicatedStorage.Remotes
local Event = Remotes:WaitForChild('UpgraderClient')
local EventSend = Remotes:WaitForChild('UpgradeFinal')
---
local currentNumber = Multiplier1.Value
local baseCost = 50000
local costMultiplier = 1.25
---
local formatNumber = (function (n)
n = tostring(n)
return n:reverse():gsub("%d%d%d", "%1,"):reverse():gsub("^,", "")
end)
local function calculateUpgradeCost(currentNumber)
return math.floor( baseCost * (costMultiplier ^ currentNumber) )
end
---
local Cost = calculateUpgradeCost(currentNumber)
local function setInitialValues()
NextPrice.Text = '$'.. formatNumber(Cost)
CurrentMulti.Text = 'X '.. Multiplier1.Value
if Multiplier1.Value >= 2 then
NextMulti.Text = 'MAX'
elseif Multiplier1.Value <= 1.95 then
NextMulti.Text = 'X ' .. Multiplier1.Value + 0.05
end
end
setInitialValues()
---
Multiplier1.Changed:Connect(function(nextval)
Cost = calculateUpgradeCost(nextval)
NextPrice.Text = '$'.. formatNumber(Cost)
CurrentMulti.Text = 'X '.. Multiplier1.Value
if Multiplier1.Value >= 2 then
NextMulti.Text = 'MAX'
elseif Multiplier1.Value <= 1.95 then
NextMulti.Text = 'X ' .. Multiplier1.Value + 0.05
end
end)
UpgradeButton.Activated:Connect(function()
if Multiplier1.Value == 2 then return end
local valToTake = EventSend:FireServer(player)
end)
MainFrame.CloseButton.Activated:Connect(function()
ScreenGui.Enabled = false
end)
Event.OnClientEvent:Connect(function()
ScreenGui.Enabled = true
end)