i have an issue where the handleM1() function is firing multiple times due to the user input, I added a print statement to make sure it wasn’t an issue with the function but rather the uis itself
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UIS = game:GetService("UserInputService")
local Players = game:GetService("Players")
local M1Event = ReplicatedStorage:WaitForChild("RemoteEvents").Combat.M1
local UptiltEvent = ReplicatedStorage:WaitForChild("RemoteEvents").Combat.Uptilt
local weaponinfo = require(ReplicatedStorage:WaitForChild("Modules").Weaponinfo)
local player = Players.LocalPlayer
local char, humanoid, hrp
local AnimPlayer = require(script.CombatAnimationHandler)
local MAX_COMBO = 5
local COMBO_TIMEOUT = 1.25
local ENDLAG_DURATION = 0.5
local comboCount = 0
local lastAttackTime = 0
local endlag = false
local isCtrlHeld = false
local m1Debounce = false
local function resetCombo()
comboCount = 0
lastAttackTime = 0
end
local function handleM1()
if m1Debounce then return end
m1Debounce = true
if not char or not humanoid or not hrp then
m1Debounce = false
return
end
if endlag or humanoid:GetState() == Enum.HumanoidStateType.Jumping then
m1Debounce = false
return
end
if char:GetAttribute("WeaponEquipedAndHeld") == "" then
m1Debounce = false
return
end
local weaponName = char:GetAttribute("WeaponEquipedAndHeld")
local now = tick()
if now - lastAttackTime <= COMBO_TIMEOUT then
comboCount += 1
else
comboCount = 1
end
if comboCount > MAX_COMBO then
comboCount = 1
end
lastAttackTime = now
endlag = true
AnimPlayer.PlayCombatAnims(player, weaponName, comboCount)
task.wait(0.1)
M1Event:FireServer(comboCount)
task.delay(ENDLAG_DURATION, function()
endlag = false
end)
task.delay(COMBO_TIMEOUT, function()
if tick() - lastAttackTime >= COMBO_TIMEOUT then
resetCombo()
end
end)
task.delay(0.05, function()
m1Debounce = false
end)
end
local function bindCharacter(character)
char = character
humanoid = char:WaitForChild("Humanoid")
hrp = char:WaitForChild("HumanoidRootPart")
end
player.CharacterAdded:Connect(bindCharacter)
if player.Character then
bindCharacter(player.Character)
end
------ This is where the script is bugging out specifically the else statement bellow
UIS.InputBegan:Connect(function(input, processed)
if processed then return end
if input.KeyCode == Enum.KeyCode.LeftControl or input.KeyCode == Enum.KeyCode.RightControl then
isCtrlHeld = true
end
if input.UserInputType == Enum.UserInputType.MouseButton1 then
if isCtrlHeld then
resetCombo()
AnimPlayer.PlayUptiltAnims(player)
UptiltEvent:FireServer()
else
print("Function Fired") ----- here is the error its firing twice
handleM1()
end
end
end)
UIS.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftControl or input.KeyCode == Enum.KeyCode.RightControl then
isCtrlHeld = false
end
end)
Its firing twice, as i said in the post I put a print statement next to the handleM1() to make sure that the issue was to do with the input connection rather then the actual function, the else resulting in the handleM1() function is the only one that’s firing twice
basically its a combat system where a person after pressing mousebutton1 launches an attack however if the player presses crtl + m1 then it will fire an event that will lift the player up for an air combo. so the else portion of the if statement is run whenever the player press mouse button 1 without holding ctrl
I have a hitbox script in the serverscriptservice but it shouldnt effect it, also for the double mouse button 1 thing the first press only fires once however the second and subsequent mouse button 1’s input fire twice, could u test the code again and see if it also does that for you?
yk the line handlem1() the whole else section, the first time u press mouse button 1 it works correctly and runs function and prints statement like expected however, once you try to press mouse button 1 again it runs the print statement and function twice, this continues to happens again and again.
Tldr: pressing mouse button 1 runs else section like normal pressing it anytime after it runs it twice
i tested it out again, seems like the user input works correctly, i think i know where the issue is commign from.
this script was dmging twice so i thought it was firing function twice, however now i have no idea how to fix it, im pretty sure its due to the fact the im use the client property.
edit: i added a print statement in the bindableevent at the very bottum where the player dmg is occuring, however it only prints once while dmg is doubled. this is VERY strange
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local HitboxClass = require(ReplicatedStorage.Modules.HitboxClass)
local HitboxTypes = require(ReplicatedStorage.Modules.HitboxClass.Types)
local Dodamage = ReplicatedStorage.BindableEvents.Damage
local weaponinfo = require(ReplicatedStorage.Modules.Weaponinfo)
local M1Event = ReplicatedStorage:WaitForChild("RemoteEvents").Combat.M1
M1Event.OnServerEvent:Connect(function(player)
local char = player.Character
if not (char and char.PrimaryPart) then return end
local hrp = char:FindFirstChild("HumanoidRootPart")
if not hrp then return end
local weaponname = char:GetAttribute("WeaponEquipedAndHeld")
if not weaponname then return end
local weaponData = weaponinfo.Weapons[weaponname]
if not weaponData then return end
local dmg = weaponData.Damage
local range = weaponData.SwingRange
local params : HitboxTypes.HitboxParams = {
SizeOrPart = Vector3.new(5, 4, range),
SpatialOption = "InBox",
DebounceTime = 5,
Debris = 0.3,
Debug = true,
Blacklist = { char },
LookingFor = "Humanoid",
VelocityPrediction = true,
UseClient = player,
}
local hitbox, created = HitboxClass.new(params)
if not created then
warn("Hitbox creation failed")
return
end
hitbox:WeldTo(hrp, CFrame.new(0, 0, -5))
local alreadyHit = {}
hitbox.HitSomeone:Connect(function(victims)
for _, victim in ipairs(victims) do
local victumHum = victim:FindFirstChild("Humanoid")
if victumHum and not alreadyHit[victumHum] then
alreadyHit[victumHum] = true
Dodamage:Fire(victumHum, dmg)
end
end
end)
hitbox:Start()
end)
Dodamage.Event:Connect(function(victumHum, dmg)
victumHum:TakeDamage(dmg)
print("Runs")
end)