I made this local script, where it sucessfully changed the player’s walksound to be my selected id, but when changing the pitch depending on the player’s speed it doesn’t achieve anything.
local sound = script.Parent.HumanoidRootPart:WaitForChild("Running")
local humanoid = script.Parent:FindFirstChild("Humanoid")
sound.SoundId = ("rbxassetid://9083849830")
sound.PlaybackSpeed = 1
while true do
if humanoid.WalkSpeed == 25 then
sound.PlaybackSpeed = 1.2
end
if humanoid.WalkSpeed == 14 then
sound.PlaybackSpeed = 1
end
end
I’m not sure if you’re asking to change the sound speed rather than the pitch. You can’t set a sounds pitch but you can set its speed. Here’s some code for changing the sound depending on their walk speed
local humanoid = script.Parent:FindFirstChild("Humanoid")
sound.SoundId = ("rbxassetid://9083849830")
sound.PlaybackSpeed = 1
while true do
sound.PlaybackSpeed = 16 / humanoid.WalkSpeed
task.wait(0.05)
end
Also be sure that your script is a local script since the object doesn’t exist on the server
i meant sound speed, woops
However, when i try your script whenever the player’s speed is set to my target speed (of 25) the sound slows down rather than speeding up.
You could also change the while true loop to a changed event for extra optimization
local sound = script.Parent.HumanoidRootPart:WaitForChild("Running")
local humanoid = script.Parent:FindFirstChild("Humanoid")
sound.SoundId = ("rbxassetid://9083849830")
sound.PlaybackSpeed = 1
humanoid.Changed:Connect(function(property)
if property == "WalkSpeed" then
if humanoid.WalkSpeed == 25 then
sound.PlaybackSpeed = 1.2
end
if humanoid.WalkSpeed == 14 then
sound.PlaybackSpeed = 1
end
end
end)