Value Stopping at 4.1

Kind of an update on my last post.
Basically, I have a value that I am increasing by 0.1 every 0.3 seconds until it reaches my randomly generated number. Everything works fine, except for when the value that is increasing reaches 4.1, it just stops, no matter what value it has to reach is, unless it is under 4.1

local crashLabel = script.Parent:WaitForChild("CrashAmount")
local startCrash = script.Parent.Start

startCrash.MouseButton1Click:Connect(function()
	local amount = math.random(10, 100)*.1 --Define where the game will "crash"
	local actualAmount = 1 --Where the game starts
	local value = true --uhhhhh truevalue
	print("Crash will stop at "..amount.."x") --Print where game will crash, delete later
	startCrash.Text = "Game in progress..."
	startCrash.Active = false
	wait(2)
	while value == true do
		if actualAmount < amount then --While amount displayed does not equal the actual game amount
			actualAmount += 0.1 --Add 0.1
			actualAmount *= 10 --The next 3 lines are to simplfy because sometimes weird decimals like 1.09 show up (idk why)
			actualAmount = math.floor(actualAmount)
			actualAmount = actualAmount / 10
			crashLabel.Text = actualAmount.."x" --Display current amount
			wait(0.3)
		elseif actualAmount >= amount then --Once displayed value is greater than the value it is supposed to go to, "crash"
			startCrash.Text = "Crashed!"
			value = false --End script
		end
	end
end)

Use a print statement before each if check, like

while value == true do 
    print (actualAmout," ", amount)  
    if actualAmount < amount then

to see where the issue lies.
Don’t forget that Floating Point decimal errors can cause issues like your computer trying to compare 4 to 3.999999999.

1 Like