RemoteEvents not being reveived by the server if the are more instances of the same script

So I made a client-server system for detecting button click on SurfaceGUIs.
It works properly if there’s one instance of the model the script is in, but if there’s more only the first one added receives btnActivated.

Server

function f.onClick(button:GuiButton,func)
	if f.root.Name == "NerdTV2" then
		print("connected") --prints
	end
	if not button:IsA("GuiButton") then error("Not a button") end
	if (typeof(func) ~= "function") and (typeof(func) ~= "BindableFunction") then error("Not a function or BindableFunction") end
	local con = f.c2s.btnActivated.OnServerEvent:Connect(function(plr,btn:GuiButton)
		if f.root.Name == "NerdTV2" then
			print("worked") --does not print
		end
		if not btn then return end
		if button ~= btn then return end
		if not f.utils.isVisibleInTree(button) then  return false end
		if typeof(func) == "function" then
			func(plr)
		elseif typeof(func) == "BindableFunction" then
			func:Fire(plr)
		end
	end)

	return con
end

Client

function connect(btn:GuiButton)
	if not btn then return end
	if not btn:IsA("GuiButton") then return end
	if table.find(connected,btn) then return end
	table.insert(connected,btn)
	btn.Activated:Connect(function()
		c2s.btnActivated:FireServer(btn) -- i tested it before, always fires
	end)
end

The original model is named NerdTV and the copy is named NerdTV2.
Both use the same c2s (stands for client to server) instance in ReplicatedStorage.

	local a = Instance.new("Configuration")
	a.Name = f.root.Name
	a.Parent = f.c2s.btnActivated

I added this to onClick and all objects have names of the first instance which means they use other btnActivated

The issue seems to be in the deployment process when c2s is moved from the main script to ReplicatedStorage.
I replaced

f.c2s = f.kernel.c2s.Value

with

f.c2s = game:GetService("ReplicatedStorage"):WaitForChild(f.kernel.c2s.Value.Name)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.