Hey, I want to put code in this while wait and if statement without it looping a bunch how can I do this?

Hello, Here is my code

spawn(function()
	while wait() do
		if TENRELsystem:Check_TENREL_Level() == 1 then
			print("1")
			
			movementController.footstepSounds.Volume = 0.0069
		elseif TENRELsystem:Check_TENREL_Level() == 2 then
			print("2")
			movementController.footstepSounds.Volume = 0.049
		elseif TENRELsystem:Check_TENREL_Level() == 3 then
			print("3")
			movementController.footstepSounds.Volume = 0.29
		end
	end
end)

the TENRELsystem:Check_TENREL_Level() is just a module script function that will return an int.
inside the first TENRELsystem:Check_TENREL_Level() == 1 I want to run code that will make the player breath and frost smoke will come out of their mouth the problem is I need the breathing sound and the frost smoke to be also looped. And that’s a problem because this loop is looping that loop if that makes sense.

I’m not exactly sure what you need help with but you could just put a wait or debounce to stop it from looping a lot.

The problem I have is I have a loop while wait() do checking if the values change now if the value == 1 then it will play a heartbeat sound if it doesnt = 1 it will stop the heart beat sound and not play it the problem is it keeps looping and loops the code inside the if statement which will keep looping the sound which will not play the sound.

You can store the integer in an IntValue object and use the .Changed event to listen when the value is changed:

IntValue.Changed:Connect(function(newValue)
    -- Code goes here
end)

the problem is it keeps looping and loops the code inside the if statement which will keep looping the sound which will not play the sound.

What? It loops the sound but won’t play it? Also, why aren’t you doing a while true do with a wait inside of it?