I was trying to make a simple program which would run in a while loop until the players health is 0 but instead, it goes to a floating point number after two calculations. Here is the output:
( I did this with the print function)
This is the code I used to achieve this:
while humanoid.Health > 0 do
humanoid.Health = humanoid.Health - 10
print(humanoid.Health)
wait(0.5)
end
I know about Math.Round but still, I thought floating point errors only appears when adding or subtracting by decimal numbers, this might be a little inefficient due to it needing to do a math operation each time but I’m fine with it for now.
This is occurring due to the default ‘Health’ script that gets cloned into each player’s character (whenever it is added/spawned), if you want to remove this behavior you can place an empty server script named “Health” into the ‘StarterCharacterScripts’ container, this will override the default ‘Health’ script.