null nil false Sound false LocalSound 0.5 then Util.Resume(sound) setSoundInPlayingLoopedSounds(sound) else stopPlayingLoopedSoundsExcept() end end; [Enum.HumanoidStateType.Swimming] = function() if activeState ~= Enum.HumanoidStateType.Swimming and Util.VerticalSpeed(Head) > 0.1 then local splashSound = Sounds[SFX.Splash] splashSound.Volume = Util.Clamp( Util.YForLineGivenXAndTwoPts( Util.VerticalSpeed(Head), 100, 0.28, 350, 1), 0,1) Util.Play(splashSound) end do local sound = Sounds[SFX.Swimming] stopPlayingLoopedSoundsExcept(sound) Util.Resume(sound) setSoundInPlayingLoopedSounds(sound) end end; [Enum.HumanoidStateType.Climbing] = function() local sound = Sounds[SFX.Climbing] if Util.VerticalSpeed(Head) > 0.1 then Util.Resume(sound) stopPlayingLoopedSoundsExcept(sound) else stopPlayingLoopedSoundsExcept() end setSoundInPlayingLoopedSounds(sound) end; [Enum.HumanoidStateType.Jumping] = function() if activeState == Enum.HumanoidStateType.Jumping then return end stopPlayingLoopedSoundsExcept() local sound = Sounds[SFX.Jumping] Util.Play(sound) end; [Enum.HumanoidStateType.GettingUp] = function() stopPlayingLoopedSoundsExcept() local sound = Sounds[SFX.GettingUp] Util.Play(sound) end; [Enum.HumanoidStateType.Freefall] = function() if activeState == Enum.HumanoidStateType.Freefall then return end local sound = Sounds[SFX.FreeFalling] sound.Volume = 0 stopPlayingLoopedSoundsExcept() end; [Enum.HumanoidStateType.FallingDown] = function() stopPlayingLoopedSoundsExcept() end; [Enum.HumanoidStateType.Landed] = function() stopPlayingLoopedSoundsExcept() if Util.VerticalSpeed(Head) > 75 then local landingSound = Sounds[SFX.Landing] landingSound.Volume = Util.Clamp( Util.YForLineGivenXAndTwoPts( Util.VerticalSpeed(Head), 50, 0, 100, 1), 0,1) Util.Play(landingSound) end end; [Enum.HumanoidStateType.Seated] = function() stopPlayingLoopedSoundsExcept() end; } -- Handle state event fired or OnChange fired function stateUpdated(state) if stateUpdateHandler[state] ~= nil then stateUpdateHandler[state]() end activeState = state end Humanoid.Died:connect( function() stateUpdated(Enum.HumanoidStateType.Dead) end) Humanoid.Running:connect( function() stateUpdated(Enum.HumanoidStateType.Running) end) Humanoid.Swimming:connect( function() stateUpdated(Enum.HumanoidStateType.Swimming) end) Humanoid.Climbing:connect( function() stateUpdated(Enum.HumanoidStateType.Climbing) end) Humanoid.Jumping:connect( function() stateUpdated(Enum.HumanoidStateType.Jumping) end) Humanoid.GettingUp:connect( function() stateUpdated(Enum.HumanoidStateType.GettingUp) end) Humanoid.FreeFalling:connect( function() stateUpdated(Enum.HumanoidStateType.Freefall) end) Humanoid.FallingDown:connect( function() stateUpdated(Enum.HumanoidStateType.FallingDown) end) -- required for proper handling of Landed event Humanoid.StateChanged:connect(function(old, new) stateUpdated(new) end) function onUpdate(stepDeltaSeconds, tickSpeedSeconds) local stepScale = stepDeltaSeconds / tickSpeedSeconds do local sound = Sounds[SFX.FreeFalling] if activeState == Enum.HumanoidStateType.Freefall then if Head.Velocity.Y < 0 and Util.VerticalSpeed(Head) > 75 then Util.Resume(sound) --Volume takes 1.1 seconds to go from volume 0 to 1 local ANIMATION_LENGTH_SECONDS = 1.1 local normalizedIncrement = tickSpeedSeconds / ANIMATION_LENGTH_SECONDS sound.Volume = Util.Clamp(sound.Volume + normalizedIncrement * stepScale, 0, 1) else sound.Volume = 0 end else Util.Pause(sound) end end do local sound = Sounds[SFX.Running] if activeState == Enum.HumanoidStateType.Running then if Util.HorizontalSpeed(Head) < 0.5 then Util.Pause(sound) end end end end local lastTick = tick() local TICK_SPEED_SECONDS = 0.25 while true do onUpdate(tick() - lastTick,TICK_SPEED_SECONDS) lastTick = tick() wait(TICK_SPEED_SECONDS) end end ]]>