Weird remote event behavior

I’ve made a skill framework , but for some reason firing remote events to the server causes it to replicate each time you use it. For example, the first time you use it the server recieves it once, then the second time it recieves it twice, then 3 times, 4, 5, etc. It’s weird and i dont know what the fix is.
Client:

local Player = game.Players.LocalPlayer
local Character = script.Parent

local UserInputService = game:GetService("UserInputService")
local RS = game:GetService("ReplicatedStorage")

local Server = RS.Remotes.Server
local InputRemote = RS.Remotes.Inputs
local EffectEvent = RS.Remotes.VFX

local Skillsets = require(RS.Modules.Skillsets)
local BaseEffects = {}
local Required = {}

local Availablesets = {
	"TestSkillSet",
}

local InputBegan = coroutine.create(function()
	UserInputService.InputBegan:Connect(function(UserInput,GPE)
		if GPE then return end
		local Skill, Set, Info, Input = nil, nil, nil, nil
		if UserInput.UserInputType == Enum.UserInputType.MouseButton1 then
			Input = "M1"
				Info = {Data = "Test"}
		else
			Input = UserInput.KeyCode.Name
			Info = {Data = "Test"}
		end

		for i, v in pairs(Availablesets) do
			if Skillsets[v] then
				if Skillsets[v][Input] then
					Skill = Skillsets[v][Input]
					Set = v
				end
			end
		end
		if Skill then
				InputRemote:FireServer("InputBegan", UserInput.KeyCode.Name)
					local Fire = Server:FireServer(Skill["Name"], Set, Info)
		end
	end)
end)

local InputEnded = coroutine.create(function()
	UserInputService.InputEnded:Connect(function(Input, GPE)
		if Character:GetAttribute("Attacking") == true then 
			print("InputEnded")
			InputRemote:FireServer("InputEnded", Input.KeyCode.Name)
		end
	end)
end)

coroutine.resume(InputBegan)
coroutine.resume(InputEnded)

EffectEvent.OnClientEvent:Connect(function(...)
	local SkillSetName, Params = unpack(...)
	print(SkillSetName, Params)
	local Module
	for i, v in pairs(script:GetDescendants()) do
		if v:IsA("ModuleScript") then
			if v.Name == SkillSetName then
				Module = v
			end
		end
	end
	local Remote = game.ReplicatedStorage.Remotes.Test
		Module = require(Module)
		Module[Params["FXName"]](Player, Params)
end)

Server:

local RS = game:GetService("ReplicatedStorage")

local ServerRemote = RS.Remotes.Server

local Inputs = require(RS.Modules.Inputs)
local Functions = require(RS.Modules.Functions)
local CV = require(game.ServerStorage.Modules.CombatValues)
local AVS = require(game.ServerStorage.Modules.AvailableSets)
local Cooldowns = require(game.ServerStorage.Modules.Cooldown)


ServerRemote.OnServerEvent:Connect(function(Player, SkillName, SkillSet, Data)
	local C = CV[Player.Character]
	local AvailableSets = AVS[Player.Character]
	if not AvailableSets[SkillSet] or Cooldowns:CheckCooldown(SkillName, Player) then return end
	print("SetAvailable!")
	if not C.Stunned or not C.Attacking then
		local module
		module = require(script.Skills[SkillSet])
		module[SkillName](Player, Data)
	end
end)

Server module that recieves the remote event:

local Functions = require(game.ReplicatedStorage.Modules.Functions)
local Cooldowns = require(game.ServerStorage.Modules.Cooldown)
local CV = require(game.ServerStorage.Modules.CombatValues)
local Remote = game.ReplicatedStorage.Remotes.Test
local Test = {
	["Test"] = function(Player, ...)
		local Character = Player.Character
		local C = CV[Character]
		C.Attacking = true
		task.delay(1, function()
			C.Attacking = false
		end)
		Functions.FireClientWithDistance(
			{Origin = Character.HumanoidRootPart.Position, 
				Distance = 125, 
				Remote = game.ReplicatedStorage.Remotes.VFX}, 
			{"TestSkillSet", {FXName = "Test" , Data = {Character = Character},} })
		Cooldowns:AddCooldown("Test", 3, Player)
		Remote.OnServerEvent:Connect(function(player)
			print("serverrecievedfromclient")
		end)
	end,
	["Test2"] = function(Player, ...)
		local Character = Player.Character
		local C = CV[Character]
		C.Attacking = true
		task.delay(1, function()
			C.Attacking = false
		end)
		Cooldowns:AddCooldown("Test2", 3, Player)
	end,
}
return Test

Client Module that fires the event:

local Remote = game.ReplicatedStorage.Remotes.Test
local TestSkillSet = {
["Test"] = function(Player, Params)
		Remote:FireServer()
	end,
}
return TestSkillSet
1 Like

That probably come from the script you use to fire the remote event, would help if you show the code.

Let me edit it with the client and server script

if i can send videos on here i can show you what happens in game

There is multiple remotes, i guess the one which is duplicating is the “Test” one right ?

yes it is sorry for the confusion, the server remote is irrelevant, and the VFX remote is for client side effects, it fires from the server and the client receives it, requires the module with the name sent through the remote and the module that was required is firing the test event which the server is receiving multiple times

used once:
Screenshot_181
used 4 times:

Not sure, but i think it come from your client script and your client module, you’re currently firing the same remote multiple time, then it may stack together over time.

In this function

EffectEvent.OnClientEvent:Connect(function(...)
	local SkillSetName, Params = unpack(...)
	print(SkillSetName, Params)
	local Module
	for i, v in pairs(script:GetDescendants()) do
		if v:IsA("ModuleScript") then
			if v.Name == SkillSetName then
				Module = v
			end
		end
	end
	local Remote = game.ReplicatedStorage.Remotes.Test
	Remote:FireServer() --Firing one time
	Module = require(Module) --Firing another time
	Module[Params["FXName"]](Player, Params)
end)

oh yeah that, i removed that, i was just testing if it was the client module, it wasn’t. The server is receiving it multiple times i fired the remote from the client handler script which is a normal local script and it still received multiple times.

Alright, so the problem can come from the FireClient of the EffectEvent then, but i didn’t found where it is on your server script or module, there is no fire client on the VFX remote in your code ^^

Oh yes, sorry that’s in a separate module and thats what the Functions.FireClientWithDistance is.
Module:

local rp = game:GetService("ReplicatedStorage")
local VFXRemote = rp.Remotes.VFX
local Functions = {
["FireClientWithDistance"] = function(Args, ...)
	for i, P in pairs(game.Players:GetChildren()) do
		local CharModel = P.Character
			if (Args.Origin - CharModel.HumanoidRootPart.Position).Magnitude <= Args.Distance then
				Args.Remote:FireClient(game.Players:GetPlayerFromCharacter(CharModel), ...)
		end
	end
end,
}
return Functions
1 Like

Oh yeah that’s maybe why it is stacking, did you tried to add a break on the for do loop ?
Edit: You can also use FireAllClient if you want to play VFX to all players

local rp = game:GetService("ReplicatedStorage")
local VFXRemote = rp.Remotes.VFX
local Functions = {
	["FireClientWithDistance"] = function(Args, ...)
		for i, P in pairs(game.Players:GetChildren()) do
			local CharModel = P.Character
			if (Args.Origin - CharModel.HumanoidRootPart.Position).Magnitude <= Args.Distance then
				Args.Remote:FireClient(game.Players:GetPlayerFromCharacter(CharModel), ...)
				break
			end
		end
	end,
}
return Functions

Just tried it, thats not the problem because i have a print in the .OnClientEvent function and it doesn’t receive multiple times. the server still receives it multiple times, its not firing more than once its just receiving it more than once and i dont know why, i thought it was because i was requiring the server module over and over but im not 100% sure

Yeah i though about it too, but was not sure

I’m so confused this should be working :sob:

try to see if there are other local scripts firing the event

there isn’t it’s only that local script

I’ve made some test and it don’t come from local script or module, also i noticed in your output screenshot that only the server print is duplicating each time it is used, but not the client print, so the problem is comming from the server module

yeah that’s the conclusion I came to as well, but im not sure how to fix it

what i think is happening is that each time i require the server module, it keeps waiting for the onserverevent so it keeps duplicating over and over so i think if i just add a return to the end it’ll fix