It’s actually more than just sounds, you can even fire the remote to destroy players, character and everything since the server destroys the given object.
That’s a good idea that I thought of, but I was worried it would cause lag on the server from thousands of sounds playing (possibly).
That’s why you reuse the same sound, no reason to make a new one
That doesn’t really work for games that are multiplayer unless
for i, v in ipairs(game.Players:GetChildren()) do
local s = Instance.new("Sound", v.Character)
end
You can store the sound for the player then reuse the sound
That’s kind of what I was trying to say, but maybe a PlayerAdded would work better.
My idea is when you make a new sound see in a table if there is a sound for a player and if not then assign a key as the player then the value as the sound, otherwise, if there’s a sound then reuse it if it’s not destroyed
As harsh as it sounds, this is an extremely poor method of doing this. The level of lag this will cause (not even mentioning the remote event being spammed) will be very high.
You are indexing through every instance in the entire game (most games that will be well over 10,000) every 0.1 seconds just to find a sound that is over a playback loudness. This will not only be affecting radios, but every single sound instance in the game. An exploiter could crash a game that has this pretty easily.
I suggest you switch this to a remote event that fires to the client to monitor it. And instead of it going above 800 once, it should have to above 800 multiple times. Otherwise this is a very inefficient way of solving loud audios.
Alright, I’ll check out some other methods.
But why use a remote event if that’s not really needed? You can do all the detection on clientside with descendantadded and a single check for every descendant.
I updated the main post, tell me if this solution works.
And yes I still have the while loop, but that’s not of main importance for me right now
You haven’t changed anything, and the loop IS the problem.
Sorry but anyone whos reading this I can’t suggest you use this tutorial unless you want a broken game.
Here’s the problem yet again, relying on the client, just do it on the clientside, you can just remote:FireServer(obj,800)
and boom, not kicked.
Look at the server script where it fires RemoteEvent2
Tell me how a while true do loop breaks a game. It may not be the most memory-efficient, sure, but unless you have a potato, it’s not gonna break your game.
I didn’t even notice that. I guess I’ll work on this a bit more.
Not everyone has a good pc, like me for example, my pc is horrible and barely runs well on popular games.
You’re indexing through the entire game in a fast loop just to find a sound. You said this was made for radios to block loud sounds, but you’re indexing through every sound in the game rather than just having the server tell the client to monitor the radio sound when it is played.
I can confirm one of my projects has 10s of thousands of instances, nearly 100k workspace alone. You’re telling me that “unless you have a potato”, its just fine that every 0.1 seconds all of those instances are going to be checked for sounds to stop loud audios? This tutorial does more damage than good.
You switched gears from “while true do breaks game” to “for loop through every descendant breaks game.”
I think I have a solution: iterate through every character and find the sound. Would this work?
Iteration for every time is not the solution here, sure, you can iterate first for current sounds, but not every frame, you can use a DescendantAdded event and a for loop (only once) to make sure nothing is loud.
Thanks, hope this solves the quarrel.
Also, make sure to wrap the for loop in a protected call because you may touch coreguis and those will result in an error.