Remote event being fired once but being multiple times on the server

I am creating a system, but for some reason when I fire a remote event, the server receives it a LOT of times.

Client code:

local colorsFrame = script.Parent:WaitForChild(‘colors’)
local RE = game.ReplicatedStorage:WaitForChild(‘RemoteEvents’):WaitForChild(‘SetTycoonColor’)

local confirm = script.Parent:WaitForChild(‘confirmChangeColor’)

local sound = script.Parent.Parent:WaitForChild(‘button click’)

local plr = game:GetService(‘Players’).LocalPlayer

local colorTable = {}

local selectedColor

local db = false

task.wait(4)

local function clicked(color, button, stroke)
warn(‘Clicked!!!’)
if db == false then

	sound:Play()

	confirm.Visible = true

	local db = false

	confirm.Yes.MouseButton1Click:Connect(function()
		if not db then
			db = true

			sound:Play()

			confirm.Visible = false

			if plr.leaderstats.Cash.Value >= 50 then

				for i, button in pairs(colorsFrame:GetChildren()) do

					if button:IsA('TextButton') then

						local uiStroke = button:FindFirstChild('UIStroke')

						if uiStroke then

							uiStroke.Color = Color3.new(0,0,0)

						end

					end
				end

				table.clear(colorTable)

				warn(tostring(button.BackgroundColor3))

				for colorValue in string.gmatch(tostring(button.BackgroundColor3), "%d+%.?%d*") do
					table.insert(colorTable, tonumber(colorValue))
				end

				selectedColor = button

				stroke.Color = Color3.new(0.333333, 0.666667, 1)
				warn(db)
				RE:FireServer(colorTable)
			else
				warn(db)
				RE:FireServer(colorTable)
			end
			task.wait(0.5)

			db = false
		end


	end)

	confirm.No.MouseButton1Click:Connect(function()

		sound:Play()

		confirm.Visible = false

	end)

	task.wait(0.5)

	db = false

else

	warn('db is true')

end

end

for i, button in pairs(colorsFrame:GetChildren()) do

if button:IsA('TextButton') then
	
	local color = plr:GetAttribute('RestaurantColor')
	local uiStroke = button:FindFirstChild('UIStroke')
	
	table.clear(colorTable)
	
	for colorValue in string.gmatch(color, "%d+%.?%d*") do
		table.insert(colorTable, tonumber(colorValue))
	end
	
	warn(button.BackgroundColor3 == Color3.new(colorTable[1], colorTable[2], colorTable[3]))
	
	if tostring(button.BackgroundColor3) == color and uiStroke then
		
		warn('Loading Data...')
		
		selectedColor = button
		uiStroke.Color = Color3.new(0.333333, 0.666667, 1)
		
	end
	
	button.MouseButton1Click:Connect(function()
		clicked(color, button, uiStroke)
	end)
	
end

end

Server Code:

local RE = game.ReplicatedStorage:WaitForChild(‘RemoteEvents’):WaitForChild(‘SetTycoonColor’)
local notifcation = game.ReplicatedStorage:WaitForChild(‘RemoteEvents’):WaitForChild(‘notification’)

local setColorModule = require(script.Parent:WaitForChild(‘setColors’))

RE.OnServerEvent:Connect(function(plr, colorTable)
print(‘Received SetTycoonColor event from player:’, plr.Name)
print(‘Player Cash:’, plr.leaderstats.Cash.Value)
print(‘Color Table:’, table.concat(colorTable, ', '))

if plr.leaderstats.Cash.Value >= 50 then
	
	plr.leaderstats.Cash.Value -= 50
	
	warn(table.concat(colorTable, ", "))

	plr:SetAttribute('RestaurantColor', table.concat(colorTable, ", "))

	setColorModule.SetColors(plr, colorTable)
	
	notifcation:FireClient(plr, 'Changed color of restaurant!')
else
	notifcation:FireClient(plr, 'Color change failed, insufficient funds!')
end

end)

Any help I can get is appreciated!

1 Like

Hey, I’m making a round team select system and also met the same problem when client fire once but server receive twice. Have you found any fix?

Edit: Nvm, I found my solution from this post: Remote Event Fires More and More Each Time It's Used