Issue with hitboxclass module

So i have a combat system, where it fires a remote event to the server to create the hitbox, using the hitbox class module, I used the client property to replicate it to the client, however the dmg is processing twice instead of once, how wold I fix this without changing the overall structure


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.RemoteEvents.Combat.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
				print(player.Name, "hit", victim.Name)
				Dodamage:Fire(victumHum, dmg)
			end
		end
	end)

	hitbox:Start()
end)


Dodamage.Event:Connect(function(victumHum, dmg)
	victumHum:TakeDamage(dmg)
	print("Target HP after hit:", victumHum.Health)
end)

probably M1Event firing twice? its impossible to tell how with the current info; best guess is that if you have it within a ContextActionService bind and aren’t checking UserInputState, then it might be firing on mouse release as well as mouse down

its also a bit confusing bc Dodamage is in the RemoteEvents folder but is being treated as a normal BindableEvent, maybe look into whether or not some other script is interacting with it

1 Like

Your right i found the issue, it was firing multiple times

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