Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Is There A Way To Play A Sound When The Player Reaches Its Max Walkspeed?

Asked by 7 years ago

I was wondering if there is a way to make it so when the player reaches a certain walk speed it plays a sound? I have an ATST and when the player reaches a certain walkspeed I want it to play the walking sound.

Thank you for your time.

1 answer

Log in to vote
2
Answered by 7 years ago

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:

-- Get all player character components
local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

-- Perhaps the speed they need to reach or exceed to play the sound
local SPEED_ALERT = 50

-- Quick refs
local floor = math.floor

-- Callback to humanoid's Running event
local function playSoundOnSpeed(speed)
    speed = floor(speed)
    if speed >= SPEED_ALERT then
        print("Speed exceeded, playing sound")
    end
end

-- Connect function to event
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.

Ad

Answer this question