Can't change pitch of running sound

I’m trying to increase the pitch of the player’s walking sound when they’re running. The only solution I’ve found so far only works on the client, but I want that effect to take place on the server as well. So, I created a server-side script inside StarterCharacterScripts. However, for some reason it doesn’t do anything. There are no errors, and it prints everything correctly except for the “ok” part, which means that GetPropertyChangedSignal is not being listened to correctly. Why?

local character = script.Parent

local Hum = character:WaitForChild("Humanoid")
local HRP = character:WaitForChild("HumanoidRootPart")

local defaultWalkSpeed = 16
local maxWalkSpeed = 25

local defaultPlaybackSpeed = 0.9
local maxPlaybackSpeed = 1.25

print("loaded")

if Hum then
	print('yes1')
end

if HRP then
	print('yes2')
end

Hum:GetPropertyChangedSignal("WalkSpeed"):Connect(function()
	print("ok")
	local walkSpeed = Hum.WalkSpeed

	local playbackSpeed = defaultPlaybackSpeed + (walkSpeed - defaultWalkSpeed) / (maxWalkSpeed - defaultWalkSpeed) * (maxPlaybackSpeed - defaultPlaybackSpeed)

	playbackSpeed = math.clamp(playbackSpeed, defaultPlaybackSpeed, maxPlaybackSpeed)

	HRP.Running.PlaybackSpeed = playbackSpeed
end)

if you know any other alternative ways to change the walk playbackSpeed on the server when the player is running please let me know

2 Likes

Use RemoteEvent.Send when walkspeed property changes and Server should update it.

This is the best solution for you.

2 Likes

I appreciate the reply, yeah ive been thinking about remote events and thats how i did it:

local character = script.Parent

local Hum = character:WaitForChild("Humanoid")
local HRP = character:WaitForChild("HumanoidRootPart")

local RS = game:GetService("ReplicatedStorage")
local RunSpeedChanged = RS:WaitForChild("RunSpeedChanged")

local defaultWalkSpeed = 16
local maxWalkSpeed = 25

local defaultPlaybackSpeed = 0.9
local maxPlaybackSpeed = 1.25

print("loaded")

if Hum then
	print('yes1')
end

if HRP then
	print('yes1')
end

RunSpeedChanged.OnServerEvent:Connect(function(player)
	print("ok")
	local walkSpeed = Hum.WalkSpeed

	local playbackSpeed = defaultPlaybackSpeed + (walkSpeed - defaultWalkSpeed) / (maxWalkSpeed - defaultWalkSpeed) * (maxPlaybackSpeed - defaultPlaybackSpeed)

	playbackSpeed = math.clamp(playbackSpeed, defaultPlaybackSpeed, maxPlaybackSpeed)

	Hum.Running.PlaybackSpeed = playbackSpeed
end)

but for some reason it gave me this error: PlaybackSpeed cannot be assigned to

Then, in a similar post like this one, it is stated that it doesn’t matter if it runs on the client because it will work on the server, but that’s false? Players cannot notice the playback speed changes that are done on a client, only the client itself can hear the changes, not everyone on the server. This is a big issue, but thank you anyway for your help.

also i changed Hum.Running.PlaybackSpeed = playbackSpeed to HRP.Running.PlaybackSpeed = playbackSpeed because running is not a child of the humanoid

If anyone knows a solution for this, I’d be very grateful because I’ve had this problem for months now.

sorry for lating :crying_cat_face:
let me help you >=)
the reason why you are getting it because you have earned achievement! and it is: congrulations a small error

Hum.Running.PlaybackSpeed = playbackSpeed u setting the Hum not HRP :rage:

My fault for not reading your messages that sent :fearful:

If running is not child of it then try using the findfirstchild if object exists.

1 Like

thank, but isnt running a proprety? and not a object? if i use findfirstchild it will return nil

its a object in humanoidrootpart.also the Running thing on the Hum is the event triggered when player walks.

1 Like
	local running = HRP:FindFirstChild("Running")
	if running then
		print("ok2")
	else
		warn("no")
	end

weird, it printed “no”, it cant find the object “running” in humanoidrootpart

idk why roblox makes it so difficult to change running pitch :sob:

You should consider this: The server shouldn’t bother with anything related to sounds. You want this effect on the server because you want it to propagate to other clients correct? In that case you should just have the other clients’ characters hook into this behavior on your client instead of forcing the server to do this.

Create a client-sided script and listen in on when any player joins. Then listen for when their character gets added. Upon the character being added, you can wait for the humanoid to exist and hook in like you normally do.
This is typically where I’d say hook into WalkSpeed changed, but you can’t do that since you’re working with other clients as well as your own (WalkSpeed property wont change on other clients). Instead you should listen for when their HRP’s AssemblyLinearVelocity changes:

HumanoidRootPart:GetPropertyChangedSignal("AssemblyLinearVelocity"):Connect(function()
    -- We multiply by the end vector so we ignore any Y changes
    local velocity = HumanoidRootPart.AssemblyLinearVelocity * Vector3.new(1, 0, 1)
    local walkSpeed = velocity.Magnitude
    local playbackSpeed = defaultPlaybackSpeed + (walkSpeed - defaultWalkSpeed) / (maxWalkSpeed - defaultWalkSpeed) * (maxPlaybackSpeed - defaultPlaybackSpeed)
    -- etc
end)

Also if you’re unsure how to hook into all characters on the client, refer to this post!

2 Likes

First of all - running sounds aren’t necessary to be played on the server. Secondly, this is a lot easier than you think. Instead of using the WalkSpeed property, you can use Humanoid.Running to get the characters’s current speed instantly.

local defaultPitch = Hum.Running.PlaybackSpeed
local defaultSpeed = Hum.WalkSpeed

Hum.Running:Connect(function(speed)
	Hum.Running.PlaybackSpeed = (speed/defaultSpeed) * defaultPitch

	--if you feel it is necessary be changed on the server, this can be run on a server script as well.
end)
1 Like

I can’t change the playbackspeed from the humanoid else it will result in a error saying PlaybackSpeed is not a valid member of RBXScriptSignal

But you’re right that using the walkspeed is unnecessary, i’ve simplified the script so that it changes the playbackspeed on a specific number when running like this:

	local HRP = character:WaitForChild("HumanoidRootPart")
	if isRunning and isWalking then
		Hum.WalkSpeed = runSpeed
		HRP.Running.PlaybackSpeed = 2
--animation handling here, not necessary to mention
	else
		Hum.WalkSpeed = 16 
		HRP.Running.PlaybackSpeed = 1
--animation handling here, not necessary to mention
	end

Now, the thing is that this is running on the client, not on the server. Idk why everyone is telling me that this can work fine on the client, but it doesn’t because other players can’t notice the changes. I’ve made a video here to show what I’m trying to say:

First of all that was my bad, it should’ve been HRP.Running.

About the client-server stuff - yes, changing the pitch on the client won’t replicate to the server. But Roblox development (at least from my perspective) is all about saving memory to keep performance high and minimalize server lag. If it’s not a fundamental feature that ALL players on the server MUST see, you should probably run it on the client. This way it’ll not only be a lot smoother but it’ll reduce the server’s workload for more important things.

Not a big deal, I know. There’s nothing wrong with running it on the server. But small things like the pitch of the running sound most likely wouldn’t be noticed by other players anyway.

1 Like
local function CharacterAdded(char)
	local HRP = char:WaitForChild("HumanoidRootPart")
	
	--i don't know what to do here
end

local function PlayerAdded(player)
	player.CharacterAdded:Connect(CharacterAdded)

	local char = player.Character
	if char then
		CharacterAdded(char)
	end
end

game.Players.PlayerAdded:Connect(PlayerAdded)

for i,v in pairs(game.Players:GetPlayers()) do
	PlayerAdded(v)
end

Thank you for replying,

I’ve tried to do something here, but as explained above, the playback speed only changes when the player is RUNNING, not WALKING. We could say that I can just use events, but what if a player is spamming the shift key? This can result in bugs and things becoming asynchronous because I’ve tried it with boolean values and the server changing it, but events are not perfect at all.

Yea true. It’s not really that big of a deal, and if I can’t fix the replication to the server side, then I’ll just let it be on the client because it’s better than nothing. The Roblox engine is not that great after all.

But I appreciate your help and the time you’ve given

1 Like