You could use the Running
event of Humanoid
, which returns the current speed the Humanoid is traveling at to it's callback. After that, you can just compare the speed it returns with whatever your speed limit is, and play the sound if the condition is met. Example:
02 | local player = game:GetService( "Players" ).LocalPlayer |
03 | local character = player.Character or player.CharacterAdded:Wait() |
04 | local humanoid = character:WaitForChild( "Humanoid" ) |
10 | local floor = math.floor |
13 | local function playSoundOnSpeed(speed) |
15 | if speed > = SPEED_ALERT then |
16 | print ( "Speed exceeded, playing sound" ) |
21 | humanoid.Running:Connect(playSoundOnSpeed) |
Just a little rough draft of how you could implement this. You'd still need to add the context for which the sound will be playing, and I'm sure there are other variables specific to your situation as well. Just let me know if you have any questions.