Why is FireServer() firing over 100 times?

Hi, so I’m trying to make a painting system for my game. However, when I fireserver() to do the event I’ve used from the client side it fires like 100 times and lags the hell out of my game. I’m unsure why this is firing so much times.

Image (when I clicked the part ONCE):

Code Source (client, this is only the bit which is acting up, the variables have been stated before):

	mouse.Button1Down:Connect(function()
		event:FireServer(mouse.Target, game.Players.LocalPlayer)
	end)

I know this must be coming from the client’s side as it’s firing the server 200 times!

Anyone know why? Help appreciated.

Have you tried using debounces?

Ye, I’ve done a debounce many times in different places, it still doesnt work

Do you have the event connection wrapped in a loop or another connection?


local deb = false
mouse.Button1Down:Connect(function()
if not deb then
		deb = true
task.wait()
event:FireServer(mouse.Target, game.Players.LocalPlayer)
end
	end)

@youfoundbull

It’s in an input changed function

Share the script that is printing the message

Can you send the code just for that portion of the script

I just tried that right now…

It dropped though right?

k

local u = game:GetService('UserInputService')
local plr = game.Players.LocalPlayer
local m = plr:GetMouse()
local event = game.ReplicatedStorage.PaintPart
u.InputChanged:Connect(function(int)
	if m.Target then
		if m.Target.Name == "WorldPiece" then
			local deb = false
			m.Button1Down:Connect(function()
				if not deb then
					deb = true
					event:FireServer(m.Target, game.Players.LocalPlayer)
				end
			end)
		end
	end
end)

Server main:

-- Server Main
local event = game.ReplicatedStorage.PaintPart

game.Players.PlayerAdded:Connect(function(plr)
	local val = Instance.new('BrickColorValue')
	val.Parent = plr
	val.Value = BrickColor.new('White')
	val.Name = "Colour"
end)

event.OnServerEvent:Connect(function(part, plr)
	plr.BrickColor = part.Colour.Value
	print(part.Name.." has painted a part.")
end)

Add task.wait() after the dev = true part.

You are connecting the function every time the input changes. So the more you move your mouse, the more times it will fire the event

1 Like

I did it

How can I make it do the same thing without input changed?

As this lags the game currently

Try this:

local plr = game.Players.LocalPlayer
local m = plr:GetMouse()
local event = game.ReplicatedStorage.PaintPart

m.Button1Down:Connect(function()
    if m.Target then
		if m.Target.Name == "WorldPiece" then
			event:FireServer(m.Target, game.Players.LocalPlayer)
		end
	end
end)

(By the way, you dont need to send the player object through the remote event, it gets passed automatically. So with how you are firing the event right now the server will see the arguments as player, target, player)

Thanks it worked

(I painted multiple parts)

1 Like

Great! Solution my post btw so people know it’s been solutioned