Number ignores limit

i want that if both statements are met that this gets executed:

local vehicleSeat = game.Workspace.Car.Chassis:FindFirstChild("VehicleSeat")
local PartEmitter = script.Parent.EngineSound.p1
local Level = script.Parent.EngineSound.WindAmbient1.DistortionSoundEffect
-------------------------------------------------------------------- this code
while task.wait() do
while vehicleSeat.Occupant and Level.Level >= 0.1 and PartEmitter.Rate <= 99 do
	task.wait(0.6)
	PartEmitter.Rate = PartEmitter.Rate + 1
end
------------------------------------------------------------------------------------------- 


	while not vehicleSeat.Occupant or Level.Level <= 0.1 and PartEmitter.Rate >= 1 do
		task.wait(0.6)
		PartEmitter.Rate = PartEmitter.Rate - 1
	end
	end

works just fine.
but the second line…

local vehicleSeat = game.Workspace.Car.Chassis:FindFirstChild("VehicleSeat")
local PartEmitter = script.Parent.EngineSound.p1
local Level = script.Parent.EngineSound.WindAmbient1.DistortionSoundEffect

while task.wait() do
while vehicleSeat.Occupant and Level.Level >= 0.1 and PartEmitter.Rate <= 99 do
	task.wait(0.6)
	PartEmitter.Rate = PartEmitter.Rate + 1
end


--------------------------------------------------------This code
	while not vehicleSeat.Occupant or Level.Level <= 0.1 and PartEmitter.Rate >= 1 do
		task.wait(0.6)
		PartEmitter.Rate = PartEmitter.Rate - 1
	end
	end
--------------------------------------------------------------------------

it doesnt work like i wanted to, if one of the statements are not met (occupant and level.level) the number should go down until it reaches 1, but it goes down as soon as i start the script, well thats what it should do but it ignores the limit, so it goes over the limit

Use maths.clamp to clamp the number to a certain number so it won’t go over below that number

2 Likes

Thank you so much it fixed my problem

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.