Issue with keeping my hitbox in the same position as when idle

Hey everyone :slight_smile: I’m trying to create my own hitbox system and it works perfectly except for one issue I’ve ran into.

The problem is, if I’m moving or the player is moving, the hitbox doesn’t stay in the same position as it is when im standing still. It moves along with the player and I want to know if there’s a way to fix this?
I’m using the mucachohitbox module for this. Thanks for reading
Also keep in mind I’m a fairly beginner scripter as you can probably tell

game.ReplicatedStorage.Remotes.Hit.OnServerEvent:Connect(function(player, damage)
	game.ReplicatedStorage.Remotes.Gui:FireClient(player)
	local character = player.Character or player.CharacterAdded:Wait()
	local module = require(game.ServerStorage.MuchachoHitbox)
	
	local params = OverlapParams.new()
	params.FilterType = Enum.RaycastFilterType.Exclude
	params.FilterDescendantsInstances = {character}
	
	local hitboxSize = Vector3.new(4.5, 9, 4)
	local hitbox = module.CreateHitbox()
	hitbox.Size = hitboxSize
	hitbox.CFrame = character.HumanoidRootPart
	hitbox.Offset = CFrame.new(0,0,-2.5)
	hitbox.Visualizer = true
	hitbox.OverlapParams = params
	
	hitbox.Touched:Connect(function(hit, hum)
		task.wait(0.13)
		hum:TakeDamage(damage)

		game.ReplicatedStorage.Remotes.GotHit:FireClient(player, hum)
		game.ReplicatedStorage.Remotes.Gui:FireClient(player, hum)
		game.ReplicatedStorage.Sounds.Hit:Play()
	end)
	
	task.wait(0.13)
	hitbox:Start()
	game.ReplicatedStorage.Sounds.Swing:Play()
	task.wait(0.13)
	hitbox:Stop()
end)

This video clip will help to see the problem I’m having
https://streamable.com/tozani

1 Like

The issue you’re facing with your hitbox system moving along with the player when they’re in motion is likely because the hitbox.CFrame is set to the HumanoidRootPart of the character. To keep the hitbox stationary relative to the character, you should set its CFrame to be an offset from the character’s root part, which remains fixed relative to the character’s position.

2 Likes

Thank you for the help, I’ve tried doing something like that but it doesn’t stay at the same fixed position relative to the torso. I’m unsure how to script this atm

1 Like

The script shows how the punch attack works, could you show where in the module it moves the hitbox?

2 Likes

I would do but I’m not sure exactly, its a huge module and has a lot of stuff I don’t understand in it. Do you have any suggestions for me to search for inside? Maybe I’m being stupid, sorry

1 Like

Just find the loop where the hitbox is moved.