Remote fired 3 times in a row why

why does my remote on mouse1 fire 3 time in a row???

Uis.InputBegan:Connect(function(input)
	for i,v in pairs(KeyCodes) do
		if input.KeyCode == v then
			Rem:FireServer(input.KeyCode.Name, true)
			print("SENT", input.KeyCode.Name, true)
		elseif input.UserInputType == Enum.UserInputType.MouseButton1 then
			Rem:FireServer("Mouse1", true)
		end
	end
end)

image

What about the script that’s receiving the :FireServer(); What is its code?

You’re looping it through a table, and depending on how much keys you have inside the KeyCodes table, is the amount of times your Event will fire when you put it in that loop

It’s better to simply just check if the value within the table you’re trying to find is actually in there by doing KeyCodes[input.KeyCode], the square brackets give you the actual value in a table, rather than the index

I also recommend including the 2nd parameter of InputBegan as it includes a gameProcessed bool that checks if the input is overlapping a function of the ROBLOX’s Core Scripts:

Uis.InputBegan:Connect(function(input, gameProcessed)
	if gameProcessed then return end
	
	if KeyCodes[input.KeyCode] then
		Rem:FireServer(input.KeyCode.Name, true)
		print("SENT", input.KeyCode.Name, true)

	elseif input.UserInputType == Enum.UserInputType.MouseButton1 then
		Rem:FireServer("Mouse1", true)
		print("SENT", input.UserInputType, true)

	end
end)
2 Likes

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