Pitchshiftsoundeffect not changing from what I set it to

Hey there! I am currently scripting a music system, and I am trying to set the octave to what the player enters. Using a remote event, I send the pitch and change it on the server script.

--creation script
local pitchsound = Instance.new("PitchShiftSoundEffect")
pitchsound.Parent = sound	
pitchsound.Name = "Pitchvalue"
pitchsound.Octave = pitch

the pitch, which I set pitchsound.octave to, was in the not working case, 0.7. (It worked when I set 0.5 or 1)
When I printed the numbers however, this is what I got

The first one is the pitch value I sent with the remote event. The second one is the value of pitch.Octave.

Can someone tell me why this happens?

Thanks :slight_smile:

This is caused by float inaccuracy due to programming limitations, pretty sure all programming languages have this and it can’t be avoided.

Think of it like this, there are fractions that we just can’t represent perfectly in decimal form, such as 1/3 = 0.33333333… and we just have to round it to something close enough. With computers its pretty much the same thing, just in base 2. Im not really sure if decimals in lua are 16 or 32 bit, but either way the difference should be negligible for most normal uses. In your case the error margin is about a millionth of a percent

1 Like