function onDied()stopLoopedSounds()for g,q in pairs((Figure:FindFirstChild("\072\101\097\100")):GetChildren())do if q and q.ClassName=="\083\111\117\110\100"then q.Volume=0 q:Stop()end end sDied.Volume=1 sDied:Play()end local g=0 local q=0 function onStateFall(N,t)g=g+1 if N then t.Volume=0 t:Play()task.spawn(function()local q=0 local N=g while q<1.5 and g==N do local g=math.max(q-.3,0)t.Volume=g task.wait(.1)q=q+.1 end end)else t:Stop()end q=math.max(q,math.abs(Head.Velocity.Y))end function onStateNoStop(g,q)if g then q:Play()end end function onRunning(g)sClimbing:Stop()sSwimming:Stop()if prevState=="\070\114\101\101\070\097\108\108"and q>.1 then local g=math.min(1.0,math.max(.0,(q-50)/110))sLanding.Volume=g sLanding:Play()q=0 end if g>.5 then sRunning:Play()sRunning.Pitch=g/8.0 else sRunning:Stop()end prevState="\082\117\110"end function onSwimming(g)if prevState~="\083\119\105\109"and g>.1 then local q=math.min(1.0,g/350)sSplash.Volume=q sSplash:Play()prevState="\083\119\105\109"end sClimbing:Stop()sRunning:Stop()sSwimming.Pitch=1.6 sSwimming:Play()end function onClimbing(g)sRunning:Stop()sSwimming:Stop()if g>.01 then sClimbing:Play()sClimbing.Pitch=g/5.5 else sClimbing:Stop()end prevState="\067\108\105\109\098"end
-- functions

function onDied()
	stopLoopedSounds()
	for _, Child in pairs(Figure:FindFirstChild("Head"):GetChildren()) do
		if Child and Child.ClassName == "Sound" then
			Child.Volume = 0
			Child:Stop()
		end
	end
	sDied.Volume = 1
	sDied:Play()
end

local fallCount = 0
local fallSpeed = 0
function onStateFall(state, sound)
	fallCount = fallCount + 1
	if state then
		sound.Volume = 0
		sound:Play()
		task.spawn(function()
			local t = 0
			local thisFall = fallCount
			while t < 1.5 and fallCount == thisFall do
				local vol = math.max(t - 0.3, 0)
				sound.Volume = vol
				task.wait(0.1)
				t = t + 0.1
			end
		end)
	else
		sound:Stop()
	end
	fallSpeed = math.max(fallSpeed, math.abs(Head.Velocity.Y))
end

function onStateNoStop(state, sound)
	if state then
		sound:Play()
	end
end

function onRunning(speed)
	sClimbing:Stop()
	sSwimming:Stop()
	if prevState == "FreeFall" and fallSpeed > 0.1 then
		local vol = math.min(1.0, math.max(0.0, (fallSpeed - 50) / 110))
		sLanding.Volume = vol
		sLanding:Play()
		fallSpeed = 0
	end
	if speed > 0.5 then
		sRunning:Play()
		sRunning.Pitch = speed / 8.0
	else
		sRunning:Stop()
	end
	prevState = "Run"
end

function onSwimming(speed)
	if prevState ~= "Swim" and speed > 0.1 then
		local volume = math.min(1.0, speed / 350)
		sSplash.Volume = volume
		sSplash:Play()
		prevState = "Swim"
	end
	sClimbing:Stop()
	sRunning:Stop()
	sSwimming.Pitch = 1.6
	sSwimming:Play()
end

function onClimbing(speed)
	sRunning:Stop()
	sSwimming:Stop()
	if speed > 0.01 then
		sClimbing:Play()
		sClimbing.Pitch = speed / 5.5
	else
		sClimbing:Stop()
	end
	prevState = "Climb"
end
