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)
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)