Hitbox not aligning correctly to where it is supposed to spawn

I want to get something close to a Forsaken-Like hitbox. Like how it trails behind the player to ensure actual hitting.

The issue is, is that the hitboxes like to trail behind. I know it’s server problems, but I want it to not trail behind so the game is more accurate.

I’ve tried setting the hitbox spawn 2 studs away from the player to 10, it gets what I want, but when I don’t move the hitbox is now too far away. No articles or anything to help with this problem.

My Client Code is this:

local uis = game.UserInputService
local Attacks = 0
local Humanoid = game.Players.LocalPlayer.Character.Humanoid
local Cooldown = false

uis.InputBegan:Connect(function(i,gpe)
	if gpe then
		return
	end
if i.UserInputType == Enum.UserInputType.MouseButton1 or i.UserInputType == Enum.UserInputType.Touch then
	if Attacks == 0 then --Attack 1
		Attacks = -1
		Humanoid:LoadAnimation(script.Attack1):Play() --Animation
		wait(0.23) --You can set this to the exact time the animation will attack
		script.RemoteEvent2:FireServer()
		local thing = 0
		while wait() do --This is to garentee the hitbox will hit the player
		thing = thing + 1
		script.RemoteEvent:FireServer()
		if thing == 13 then
			thing = 0
			break
		end
		end
		wait(1)
		Attacks = 0
	end
end
if i.UserInputType == Enum.UserInputType.MouseButton3 then
	if Attacks == 0 and Cooldown == false then
		script.RemoteEvent3:FireServer()
		Attacks = -1
		Cooldown = true
		Humanoid:LoadAnimation(script.FindPlayers):Play(0,10,1)
		wait(1.3)
		game.ReplicatedStorage.ShowAllPlayers:FireServer()
		wait(1.1)
		Attacks = 0
		wait(15)
		Cooldown = false
	end
end
end)

game.Players.LocalPlayer.PlayerGui.MobileButtons.ImageButton.InputBegan:Connect(function(i)
	if i.UserInputType == Enum.UserInputType.Touch or i.UserInputType == Enum.UserInputType.MouseButton1 then
		if Attacks == 0 and Cooldown == false then
			script.RemoteEvent3:FireServer()
			Attacks = -1
			Cooldown = true
			Humanoid:LoadAnimation(script.FindPlayers):Play(0,10,1)
			wait(1.3)
			game.ReplicatedStorage.ShowAllPlayers:FireServer()
			wait(1.1)
			Attacks = 0
			wait(15)
			Cooldown = false
		end
	end
end)

My server code is this:

local Players = game:GetService("Players")
local debounce = false

-- RemoteEvent for handling the attack
local M1Event = script.Parent.RemoteEvent
local M2 = script.Parent.RemoteEvent2

local SwingID = {
	"rbxassetid://7801336419",
	"rbxassetid://7801329626",
	"rbxassetid://7801324162"
}

M2.OnServerEvent:Connect(function(player)
	script.Parent.Parent.Knife.Trail.Enabled = true
	wait(0.2)
	local TrueSwingID = SwingID[math.random(1, #SwingID)]
	local sound = Instance.new("Sound")
	sound.SoundId = TrueSwingID --swing sound, set this to what ever you want
	sound.Parent = script.Parent.Parent.Torso
	sound:Play()
	wait(0.4)
	script.Parent.Parent.Knife.Trail.Enabled = false
	wait(1)
	sound:Destroy()
end)

-- Function to handle when the RemoteEvent is fired
M1Event.OnServerEvent:Connect(function(player)
	local character = player.Character
	if not character or not character:FindFirstChild("HumanoidRootPart") then return end

	local humanoidRootPart = character.HumanoidRootPart
	local humanoid = character:FindFirstChildOfClass("Humanoid")

	if humanoid then
		local hitbox = Instance.new("Part")
		hitbox.Size = Vector3.new(4, 6, 5)  -- Adjust size as needed
		hitbox.Position = humanoidRootPart.Position + humanoidRootPart.CFrame.LookVector * 2
		hitbox.Rotation = humanoidRootPart.Rotation-- Spawn in front of the player
		hitbox.Anchored = true
		hitbox.CanCollide = false
		hitbox.Transparency = 0.9  -- Set transparency for the hitbox turn this to 1 to make it invisible
		hitbox.BrickColor = BrickColor.new("Bright red")
		hitbox.Parent = workspace
		hitbox.Material = Enum.Material.Neon

		-- Create a touched event for the hitbox to detect collisions
		hitbox.Touched:Connect(function(part)
			local otherHumanoid = part.Parent:FindFirstChildOfClass("Humanoid")

			-- If part belongs to a humanoid (player or NPC/rig)
			if otherHumanoid and otherHumanoid.Parent ~= character and debounce == false then
				debounce = true
				if otherHumanoid.Health > 21 then
				local sound = Instance.new("Sound")
				sound.SoundId = "rbxassetid://6276679056"
				sound.Parent = otherHumanoid.Parent.Torso
				sound:Play()
				otherHumanoid:TakeDamage(20) --damageoutput
				else
					local sound = Instance.new("Sound")
					sound.SoundId = "rbxassetid://82176913611683"
					sound.Parent = otherHumanoid.Parent.Torso
					sound:Play()
					otherHumanoid:TakeDamage(1000)
					local bodyVel = Instance.new("BodyVelocity")
					bodyVel.MaxForce = Vector3.new(1,1,1) * 10000000000
					bodyVel.Velocity = Vector3.new(0,20,0) + humanoidRootPart.CFrame.LookVector * 50  
					bodyVel.Parent = otherHumanoid.RootPart
					wait(0.1)
					bodyVel:Destroy()
				end
			end
		end)

		-- Destroy the hitbox after a short period (adjust time as needed)
		wait(1)
		hitbox:Destroy()
		wait(0.1)
		debounce = false
	end
end)


Pls help, this has been a problem I’ve been dealing with for a long time.

umm, i was also makeing hitboxes like forsaken how i fixed this issue was basicly making the hitboxs spawn in the hitbox spawn in the char and not anchoreing the hitboxs and making the hitbox stay inplace a diffrent way

im gonna send a code snippet runService.RenderStepped:Connect(function() if hitbox then hitbox.CFrame = cframe hitbox.Velocity = Vector3.zero end end)

ive never used this before sorry for bad help.

I figured it was client hiboxes that fixes the problem. But it’s unreliable and bad so i’m just going to drop this forum since I already know there is no other way to fix the problem

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