Hitbox Detection issue - Ignoring Detection

I’m currently trying to make a script that uses a remote function to create a hitbox on the client and then send the info back to the server if it detects a player.

The issue is that for some reason it is not sending the information back to the server when it detects the player but instead it waits for the duration of the attack and just closes the hitbox without detecting anything.

This is the client script:

local function HitboxNew(Data)
	local Range = Data.Range
	params.FilterDescendantsInstances = {Character}

	local Hit = nil
	local Hum = nil
	local EnemyHumanoids = {}

	local hitbox = HitBoxModule.CreateHitbox()
	hitbox.Size = Vector3.new(Range,Range,Range)
	hitbox.CFrame = Character.HumanoidRootPart
	hitbox.Offset = CFrame.new(0,0,-2.5) 
	hitbox.OverlapParams = params
	hitbox.AutoDestroy = true



	hitbox.Touched:Connect(function(hit, hum)
		print("beep")
		return true,hum
	end)

	hitbox:Start()
	local Timer = 0

	task.delay(.4,function()
		EnemyHumanoids = nil
		hitbox:Stop()
		return false
	end)
end

HitboxEvent.OnClientInvoke = HitboxNew

This is the server script:

	coroutine.wrap(function()
		if Variations[PlayerCombo.ComboVariation] == nil then
			local Range = 5
			local HitResult,HitObject = HitboxRemote:InvokeClient(Player, {Range = MoveData.HitboxRange or 5})
			print(HitResult)
			print(HitObject)
			repeat
				task.wait()
			if HitResult then
				print("Worked")
			end
			until HitResult or task.wait(0.4)
			print("Check2")
		end
	end)()

If anyone could give a solution or try to explain why this is happening that it would help me out alot ty.

4 Likes

Are you using a remote function for this?

If so, don’t.
There’s a security risk that could cause the server to yield forever if an exploiter listened for a client invoke but never returned a value,
you’re better off making it send remote events both to the client then back to the server somehow.

3 Likes

Yeah just tried this and its works perfectly.

Except from the fact that when i want the information to be send back to the server, the server event is getting fired repeatedly when i only want it to be fired once for that attack

3 Likes

What does it look like on the client now that you’ve change it?

2 Likes

This is the new Client script
HitboxServer is a remote event (Client to Server)
HitboxClient is also a remote event. (Server to Client)

The issue is that Hitbox Server is being fired repeatedly for some reason

Client Script:

HitboxClient.OnClientEvent:Connect(function(Player)
	local Range = 6
	params.FilterDescendantsInstances = {Character}

	local Hit = nil
	local Hum = nil
	local EnemyChars = {}

	local hitbox = HitBoxModule.CreateHitbox()
	hitbox.Size = Vector3.new(Range,Range,Range)
	hitbox.CFrame = Character.HumanoidRootPart
	hitbox.Offset = CFrame.new(0,0,-2.5) 
	hitbox.OverlapParams = params
	hitbox.AutoDestroy = true



	hitbox.Touched:Connect(function(hit, hum)
		local Victim = hum.Parent
		EnemyChars[#EnemyChars + 1] = Victim
		
		if EnemyChars[Victim] then return end
		print(EnemyChars[Victim])
		HitboxServer:FireServer(hum)
		return 
	end)

	hitbox:Start()

	task.delay(.4,function()
		EnemyChars = nil
		hitbox:Stop()
	end)
end)

Server script:

coroutine.wrap(function()
		if Variations[PlayerCombo.ComboVariation] == nil then
			HitboxClient:FireClient(Player)
			HitboxServer.OnServerEvent:Connect(function(Player, hum)
				if hum then
					local Victim = hum.Parent
					local VRoot, VHum = Victim:FindFirstChild("HumanoidRootPart"), Victim:FindFirstChild("Humanoid")
					--
					if hum.Parent.Values.Type.Value =="NPC" then
						DamageManager.DeductDamage(Character,Victim, {Weapon = ExtraData.Weapon})

					elseif  hum.Parent.Values.Type.Value =="Player" then
						DamageManager.DeductDamage(Character,Victim, {Weapon = ExtraData.Weapon})

					end

					wait(.225)
					if NumberEvaluation == 3 and GlobalFunctions:CheckValueChar(Character, "InAir") then
						PlayerCombo.KeysLogged = 0
						PlayerCombo.ComboVariation = ""

						PlayerCombo.Hits = 0
						GlobalFunctions:AddValue("BoolValue", "Attacking", true, Character, .5)

						--VfxHandler.RemoveBodyMover(Victim)
						--VfxHandler.FaceVictim({Character = Character, Victim = Victim})
						GlobalFunctions:AddValue("BoolValue", "IFrame", true, Victim, 1.15)

						--VfxHandler.SlamDown({Character = Character, Victim = Victim, Duration = .85})
						RunService.Heartbeat:Wait()

						--NetworkStream.FireClientDistance(Character,"ClientRemote",200,{Character = Character, Victim = Victim, Module = "CombatVFX", Function = "AerialKnockBackEffect"})
						--local _ = Finishers[Data.Character] ~= nil and Finishers[Data.Character](Player,CharacterName,KeyData,MoveData,{Victim = Victim})
					end
				end
			end)
		end
	end)()
2 Likes

And the EnemyChars[Victim] check is working right? Cause that’s the only reason I’d imagine it fires multiple times.

1 Like

Idk it prints nil once.

But i dont think thats the reason since i tried putting a regular print(“Check”) above the fire server event thing and it only fires once meaning the touched function is only being detected once anyways

1 Like

you could try changing it to this and seeing just in case, if you’re not sure, but it sounds like it’s working to me. I’m not sure what else would be the issue, I might just be too tired to think right now.

if EnemyChars[Victim] then print("check working"); return end
1 Like

nope it doesnt print
it is definitely not cause of that thought since i added a regular print(“Check1”) and its only printing once but inside of the server script i added another print(“Check2”) which prints multiple times

2 Likes

Well, I’m stumped then, I’ll read over it a bit more once I figure out my own script and maybe I’ll sleep on it and check it again when I have more energy (unless you’ve fixed it by then), sorry I couldn’t fix this part!

Wait i found something interesting and a clue as to why it might keep happening.

So basically for some reason the remote events are stacking.

I found this out because i placed a regular print function at the start of OnServerEvent and when i click (m1) it prints once and then when i click again it prints twice and keeps adding on a print each time i attack. But again i am unsure as to why this is happening

I managed to fix it:

So according to this thread:

I have to disconnect the event so i did that and now it only fires the server once and disconnects it afterwards so the next time its called it doesnt fire the previous event which i still dont get but at least it works now.

1 Like

wait but now it’s just firing the previous event if that makes sense:

So

Client: Click
Server: FireClient - 1
Client: FireServer - 1
Server:Nothing
Client: Click
Server: FireClient - 2
Client: FireServer - 2
Server: 1

So its like the events are lagging behind or idk

1 Like

Nvm it’s fixed again if anyone else is having this problem check this:

2 Likes

Sorry, wasn’t on all day, glad you fixed it!

1 Like

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