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

Help on changing playback speed of audio on key press?

Asked by
areci 5
4 years ago

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?

0
http://idownvotedbecau.se/noexceptiondetails - refer to this link to see why this question may not be well-received. programmerHere 371 — 4y
0
At line 8 you should put [...] = 2 and not [...] = "2" TheRealPotatoChips 793 — 4y

1 answer

Log in to vote
0
Answered by
cegberry 432 Moderation Voter
4 years ago

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)
0
solved, thanks areci 5 — 4y
Ad

Answer this question