Delayed audio despite replicating to client

why is my sound delayed despite using a remote event to run the sound on the client side? when i used this method for running particles on the client there were no problems whatsoever.


local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Debris = game:GetService("Debris")
local RunService = game:GetService("RunService")

local clientSfx = ReplicatedStorage.RemoteEvents.Server:WaitForChild("ClientSfx")

clientSfx.OnClientEvent:Connect(function(location, SoundName, volume)
	local tagged = game:GetService("CollectionService"):GetTagged("Sound")
	for i,v in pairs(tagged) do
		if v.Name == SoundName then
			local clone = v:Clone()
			local soundpart = Instance.new("Part")
			soundpart.Anchored = true
			soundpart.CanCollide = false
			soundpart.Transparency = 1
			clone.Parent = soundpart
			soundpart.Position = location
			soundpart.Parent = workspace
			clone:Play()
			
			clone.Ended:Connect(function()
				soundpart:Destroy()
			end)
		end
	end
end)
2 Likes

I don’t think a remote event is supposed to reduce delay. It goes from the server to the client so it introduces delay.

If it’s the player is causing the event itself then it’s better to play the sound immediately on the client.

1 Like

There will also be some delay simply due to the fact that information has to travel from the client to the server and vice versa. You cannot remove this delay entirely, although you may see a shorter delay with your approach of using remotes, due to some differences in how Roblox replicates audio and handles remotes.

Another source of delay you may be experiencing is loadtimes. Consider preloading your sound ids when the player joins.

https://create.roblox.com/docs/reference/engine/classes/ContentProvider#PreloadAsync

Hope this helps.

2 Likes

An easy fix for this is to split the sound effects to client and server. Client is supposed to be heard by the client and can be heard instantly, since you play them in a local script, server are supposed to be heard by other players, when they replicate to them. Since it takes time for other players to see the hit itself, the sound should be synced.

Basically the client that hits another player doesn’t need to wait for the hit to be validated in order to hear the corresponding sound, since it’s just a sound effect. If you have designed your game logic in such a way so your client code also has some checks in place, the only situation where a client will hear a sound without a hit will be if they lag a lot or exploit.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.