Hey! I am trying to make my own Piano system.
At the moment, the client side is only registering the click on a button and will send a Remote event to the server which will play the actual sound this. This is however a bit wobbly as some remotes might be “skipped”, delayed, etc. So the sound is not always being played 1:1, if you “spam the remote”. Is there any more elegant way to fix this and make it still less in memory usage?
Play the sounds on the local client. You’ll get instant audio feedback as you press a key.
If you want other players to hear the piano, you can fire a RemoteEvent to the server that X key has been pressed on Y piano, and it’ll fire all other clients to tell them to play that note on their local client.
In real terms, other players will ‘hear’ the notes with a bit of latency compared to when they were actually pressed, but the spacing between each note should be pretty consistent which is the important part.
I see but wouldn’t that technically require 2 remotes? Would that be that good for the memory when there are like tons of remotes are being fired in such a short time or is it not enought to let the memory fall?
Just playing a sound is not worthy of a remote … Just play it right there.
Remotes can help you stop hacking but you don’t want to use them constanly over all for minor things that don’t really matter if they get hacked or not. In your case here hacking the sound would only change what they hear…
You shouldn’t have to worry about getting anywhere near the limit for RemoteEvent fires if you’re just making a piano.
One remote, something like this:
LocalScript:
local Remote = game:GetService('ReplicatedStorage'):WaitForChild('SoundRemote');
local function playSound(key, piano)
-- Play the sound
Remote:FireServer(key, piano);
end
Remote.OnClientEvent:Connect(function(key, piano)
-- Play 'key' on 'piano'
end);
Server Script:
local Remote = game:GetService('ReplicatedStorage'):WaitForChild('SoundRemote');
Remote.OnServerEvent:Connect(function(player, key, piano)
for _,plr in pairs(game:GetService('Players'):GetPlayers()) do
if (plr ~= player) then
Remote:FireClient(plr, key, piano);
end
end
end);
I don’t know how you have yours set up, so adjust it however necessary, but this should suffice for what you’re trying to do. If you’re concerned about overloading the remotes, then why not add a limit on your piano script? if (#KeysPlayedInTheLastSecond > 5) then --ignore; end
type thing.
Ah I see alright, thank you! I will probably end upt to add a small debounce of like 0.05 so that autoclickers wont extremely overload it. Also, you are not required to do
for _, plr in pairs(game:GetService("Players"):GetPlayers()) do
You can simply do:
for _, plr in game:GetService("Players"):GetPlayers() do
Just thought I’d note that out, thanks for your help tho! :>
Hacking? Exploiting more like. Nonetheless, exploiters won’t be able to do anything with the remote since it will auto-check if they have the required gamepass & if they are in the distance of the part. Also, I want to play the sound round about equally for ALL players and not just for one. Therefore, an remote is required.
No worries! Glad to help. And thank you, I know, it’s just personal preference. I do the same with my if
statements:
if (x == 3) then
Makes it easier transitioning between lua and other languages.