--Server
game:GetService("ReplicatedStorage").Remotes.RadioAllEvent.OnServerEvent:Connect(function(Player, Value, Name)
if not Owner then return end
RadioPart.SoundPart.Sound.SoundId = "rbxassetid://" .. Value
SongNameRadio.Text = Name
RadioPart.SoundPart.Sound:Play()
wait(0.3)
game:GetService("ReplicatedStorage").Remotes.PlaybackLoudness:FireClient(Player, RadioPart.SoundPart.Sound)
end)
end)
--- Client
game:GetService("ReplicatedStorage").Remotes.PlaybackLoudness.OnClientEvent:Connect(function(Sound)
Sound:GetPropertyChangedSignal("PlaybackLoudness"):Connect(function()
if Sound.PlaybackLoudness > 500 then
game:GetService("ReplicatedStorage").Remotes.PlaybackLoudness:FireServer()
end
end)
end)
--- Another part of the server
game:GetService("ReplicatedStorage").Remotes.PlaybackLoudness.OnServerEvent:Connect(function(Player)
SongNameRadio.Text = "Playing Nothing"
RadioPart.SoundPart.Sound:Stop()
end)
Once it gets the GetPropertyChangeSignal it stops there it wont do anything. Runservice works but i dont want to use Runservice.
The event only fires when the value of that property is changed. But since you inserted it with a specified value, it will not be fired until it’s changed.
For instance, Ive insert a sound which has 500 PlaybackLoudness. After a while, I connect it to the event. It doesn’t fire because the value is still the same.
Your script currently only works if the audio was only loud while it was playing and not loud at the start of the audio. I would recommended just use RunService to constantly check the loudness. It will not cause any performance issues.
Using :GetPropertyChangedSignal("PlaybackLoudness") would’ve been worse than using RenderStepped or Heartbeat anyway. Sounds aren’t ‘rendered’ in Lua, they are ‘rendered’ in the engine, a sound would have that event fire every time even less than a frame. It wouldn’t work. Audio updates a lot more than frames. Lua would get stuck easily.
Using RenderStepped or Heartbeat is what you would want here. You want it to update every frame, not everytime the volume slightly changes. After-all, they will only be able to see the update once the frame loads up.
If you’re really worried about performance, then just :Disconnect the connection once it’s not needed anymore and you’re fine.