Remote event invocation queue exhausted

Hi there, I am trying to pass a value from the client to the server using remote events. The issue is, is that I am receiving an error saying the remote event invocation queue was exhausted for replicatedstorage. I do not know what the error mean, nor how to fix it with possible solutions.

local script

local Sound = workspace.Sound
local remote = game.ReplicatedStorage.PlaybackLoudness

game:GetService('RunService').Heartbeat:Connect(function(deltaTime)
	local pl = Sound.PlaybackLoudness
	
	remote:FireServer(pl)
end)

serverscript

game:GetService('RunService').Heartbeat:Connect(function()
	remote.OnServerEvent:Connect(function(player,pl)
		print(pl)
		
	end)
end)

image

1 Like

RunService.HeartBeat runs every frame. So basically you are firing a remote event ~60 times per second, which of course cant be done, and even if can, it will be extremely heavy on performance (your game will be laggy as hell)

Oh damn. How would I be able to pass this specific value then constantly, since it’s off a sound’s playbackloudness?

There is a .Changed event that fires every time the value changes. You can put your remote event in there, because there is no reason to pass the value if it is the same

How would I do this? Would I create a number value, etc?

https://developer.roblox.com/en-us/api-reference/event/Instance/Changed

I checked there, but I’m still confused. Would I do it like this?

local Sound = workspace.Sound
local remote = game.ReplicatedStorage.PlaybackLoudness

local pl = Sound.PlaybackLoudness
pl.Changed:Connect(function(value)
	remote:FireServer(value)
end)

What’s happening is that you’re creating more and more connections with every 1/60th of a second (this will absolutely tank performance and destroy your game very quickly) — you need to firstly remove the Heartbeat connection from your server script and leave the OnServerEvent by itself.

1 Like

You only need to do OnServerEvent:Connect once, you’re creating unnecessary lag by making a connection every frame.

You dont need to wrap this in a loop lol

remote.OnServerEvent:Connect(function(player,pl)
	print(pl)
end)

What about the local script? Would I still include the changed event?

You don’t need to change the LocalScript — just be mindful of the value that the client passes to the server (clamp the value passed to the server to 0, 1000); exploiters can very easily spoof the values that are passed to the server.

So is this what I would do, because it’s still throwing me the same error.

ls

local Sound = workspace.Sound
local remote = game.ReplicatedStorage.PlaybackLoudness

game:GetService('RunService').Heartbeat:Connect(function(deltaTime)
	local pl = math.clamp(Sound.PlaybackLoudness,0,1000)

	remote:FireServer(pl)
end)

ss

local remote = game.ReplicatedStorage.PlaybackLoudness

remote.OnServerEvent:Connect(function(player,pl)
	print(pl)
end)

You can keep the .Changed event in the LocalScript, sorry for not clarifying

How would I do that in the local script, though? I’m still particularly confused since it throws me the error saying attempt to index nil value?

This doesn’t work because you are indexing .Changed from the Number Sound.PlaybackLoudness. Sound.PlaybackLoudness is a number, and therefore does not have any events or functions. The property is not an object itself – it’s just the raw type. What you want to do is get the PropertyChangedSignal of PlaybackLoudness by calling :GetPropertyChangedSignal on the sound and passing a String value "PlaybackLoudness", and then connect that signal. That would look like the following:

local Sound = workspace.Sound
local remote = game.ReplicatedStorage.PlaybackLoudness

Sound:GetPropertyChangedSignal("PlaybackLoudness"):Connect(function()
	remote:FireServer(sound.PlaybackLoudness)
end)

As a side note, are you sure you have your server script in a container that can run it (such as ServerScriptService)?

I’ve got it under a character, because I’m wanting to have this value change a speed of an animation.

Alright, with the new local script, it doesn’t throw an error but it is not printing the value from the ss.

current ls and ss:

local Sound = workspace.Sound
local remote = game.ReplicatedStorage.PlaybackLoudness

Sound:GetPropertyChangedSignal("PlaybackLoudness"):Connect(function()
	remote:FireServer(math.clamp(Sound.PlaybackLoudness,0,1000))
end)
local remote = game.ReplicatedStorage.PlaybackLoudness

remote.OnServerEvent:Connect(function(player,pl)
	print(pl)
end)

Your current implementation is not ideal; animations of characters should be played on the Client, meaning there really should be no involvement with the server when adjusting the speeds. Can I see the script you are using to play these animations?

Wait what do you mean? I tried making the script local previously, but the animation doesn’t play?

local animation = script:WaitForChild('Dance')
local humanoid = script.Parent:WaitForChild('Humanoid')
local dance = humanoid:LoadAnimation(animation)

local remote = game.ReplicatedStorage.PlaybackLoudness

remote.OnServerEvent:Connect(function(player,pl)
	print(pl)
end)

dance:play()
dance.Looped = true