Hello
I have an issue with the result of 16 - 0.2.
I’m trying to subtract 0.2 from the walk speed, but the result is:16.200001525878907
Script:
plrModel.Humanoid.WalkSpeed -= NumberValue.Value
Hello
I have an issue with the result of 16 - 0.2.
I’m trying to subtract 0.2 from the walk speed, but the result is:16.200001525878907
Script:
plrModel.Humanoid.WalkSpeed -= NumberValue.Value
Double-check if you are passing a negative value. because it may pass it like this:
-- A
local num = 16
function subtract(val)
return num -= val
end
print(subtract(-2)) --// 16.2
So, lets check if its negative instead:
local num = 16
function subtract(val)
if val > 0 then
return num -= val
end
end
print(subtract(-2)) --// nil
An easier solution would be to use math.abs
like so:
plrModel.Humanoid.WalkSpeed -= math.abs(NumberValue.Value)
if the value can be negative but @napastnikiek1 always wants to subtract
plrModel.Humanoid.WalkSpeed -= -NumberValue.Value
if the numbervalue is a negative then the difference between walkspeed and the numbervalue will count as an addition which is why it gives this result.
alternatively, you can use “+=” as it also counts as a difference if the numbervalue is a negative number.
plrModel.Humanoid.WalkSpeed += NumberValue.Value
tnx @JohhnyLegoKing, I don’t want to just subtract a negative number
the result is now correct and sorry for my english I use a translator
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.