My problem is quite simple. At one point I save a Vector3 variable. I will be comparing the Z coordinate later. I print the same value that was assigned to the Z coordinate to make sure it works and it does. It prints the correct number. However, once I reference this variable in another part of the script, it receives a value that is very similar but has a very small decimal attached. For example, 54.4 became 54.400001525879. This causes problems as I then need to compare this number in an if statement and 54.4 is not equal to 54.400001… I cannot just drop the decimal because as seen in the example, I am dealing with comparing precise numbers, down to the decimal point. Where is this decimal coming from and how can I make it work as intended? Thanks. Here is where the variable is assigned and where it is referenced:
Note: Any whole numbers or numbers with a decimal of 0.5 seem to be working correctly
table.insert(notes, Vector3.new(
(gui.ScreenGui.NoteMarker.Position.X.Scale - (1 - gui.ScreenGui.NoteBoundary.Size.X.Scale) / 2) * (1 / gui.ScreenGui.NoteBoundary.Size.X.Scale),
(gui.ScreenGui.NoteMarker.Position.Y.Scale - (1 - yscale) / 2) * (1 / yscale),
math.floor(workspace.Song.TimePosition * nps) / nps))
print(math.floor(workspace.Song.TimePosition * nps) / nps)
Note: nps stays constant most of the time
The X and Y here are irrelevant. The only value that I am comparing is the Z
Here, I cycle through the table that contains this vector3 variable and compares it to the value that was initially assigned to it. I have checked to make sure that the value that it is being compared to is the correct number.
local function GetCurrentNote()
for i = 1, #notes do
print(notes[i].Z.."z")
if notes[i].Z == math.floor(workspace.Song.TimePosition * nps) / nps then
return notes[i]
end
end
print(math.floor(workspace.Song.TimePosition * nps) / nps)
return false
end
The first print in this function is the one that contains all the decimals. The second one is fine.