Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Help on changing playback speed of audio on key press?

Hello, I have a default audio for walking, and I need help with a script that changes the audio playback speed when left shift is pressed. Sorry if the script is kinda messy, still learning

local UIS = game:GetService("UserInputService")
local KeyCode = Enum.KeyCode.LeftShift

UIS.InputBegan:Connect(function(input, event)
    if input.KeyCode == KeyCode then
		local player = game.Players.LocalPlayer
		local sound = player.HumanoidRootPart:Waitforchild("Running")--audio i need to change
		sound.PlaybackSpeed = "2"
    end
end)

I tried my best, what can I do to fix this?

2 comments

0

http://idownvotedbecau.se/noexceptiondetails - refer to this link to see why this question may not be well-received.

0

At line 8 you should put [...] = 2 and not [...] = "2"

1 answer

✓ Accepted answer

You are trying to access a HumanoidRootPart, through a player, you may want to access the player's character, not the player itself. Also :Waitforchild is not a valid method, in Lua, caps are sensitive, you can easily mess up with a wrong uppercase/lowercase letter, instead use :WaitForChild.

Read this explanation ^ to prevent future errors.

Here is your fixed script:

local UIS = game:GetService("UserInputService")
local KeyCode = Enum.KeyCode.LeftShift

UIS.InputBegan:Connect(function(input, event)
    if input.KeyCode == KeyCode then
        local player = game.Players.LocalPlayer
        local sound = player.Character.HumanoidRootPart:WaitForChild("Running")--audio i need to change
        sound.PlaybackSpeed = "2"
    end
end)

1 comment

0

solved, thanks

This discussion is preserved as it was. New answers, comments, and votes are closed.