Get Property of a Server Sound from a LocalScript

I’m working on a project where I’m syncing lights with music but I’ve come up with an obstace as I want the music to be synced with each client I’m using a ServerScript to play the music but I’m using a LocalScript for the light syncing for performance reasons, However if I try get the PlaybackLoudness (or any property for that matter) of the Sound Instance I just get 0.

So my question is how would I get the property of a server playing sound from a LocalScript.

1 Like

Try playing the sound on client instead

1 Like

How would I sync the sound accross all players then?

Maybe parse the PlaybackLoudness to the server with a remote event each time that the PlaybackLoudness value changes? I think it should work.

2 Likes

Would generally work but I’m using RunService.RenderStepped for getting the PlaybackLoudness which would be much too slow if using RemoteEvent’s

In the serverscript, you can use a separate connection for firing the PlaybackLoudness to the clients only when that value changes, rather than every frame in RenderStepped. Maybe also set up a variable for checking whether the volume has reached a certain goal so it doesn’t just fire during a tween or something. Or ask the clients to tween the volume themselves

local currentVolumeGoal

sound.Changed:Connect(function(property)
	if property ~= "PlaybackLoudness" then return end
    if sound.PlaybackLoudness ~= currentVolumeGoal then return end
	VolumeChangeEvent:FireAllClients(sound.PlaybackLoudness)
end)
1 Like

Perhaps something like this would be better

-- (Server)
local soundStartTime

function StartSound()
	soundStartTime = os.time()
	remoteEvent:FireAllClients(0)
end


function StartPlayerSound(player) -- If you want to play and synchronize to a new player.
	local currentTime = os.time() - soundStartTime
	remoteEvent:FireClient(player, currentTime)
end

-- (Client)
remoteEvent.OnClientEvent:Connect(function(position)
	sound:Play()
	sound.TimePosition = position
end)
1 Like

Fire a remotevent to all players and play the sound on local:

Remote:FireAllClients()