HitBox Acting Weird

I Dont Know how to explain but is lopsided and not infront of the player

local Special = script.Parent
Special.OnServerEvent:Connect(function(player)
	
	local hum = player.Character.Humanoid
	local Animator = hum:WaitForChild("Animator")
	local SpecialAnim = script.Parent.Animation
	local animation = Animator:LoadAnimation(SpecialAnim)
	animation:Play()
	print("Animation ended")
	hum.WalkSpeed = 16
	
	local HitBox = Instance.new("Part")
	HitBox.Position = player.Character.HumanoidRootPart.Position + Vector3.new(3,0,0)
	HitBox.Size = Vector3.new(5,5,5)
	HitBox.Name = "HitBoxPart"
	HitBox.Parent = game.Workspace
	HitBox.Transparency = 0.5
	HitBox.BrickColor = BrickColor.Red()
	HitBox.CanCollide = false
	HitBox.Anchored = true
	
	HitBox.Touched:Connect(function(otherPart)
		local otherHum = otherPart.Parent:FindFirstChild("Humanoid")
		if otherHum then
			if hum then
				if otherPart.Parent.Name == player.Name then
					return
				end
			end
			otherHum:TakeDamage(100)
		end
	end)
	game.Debris:AddItem(HitBox,1.3)
	
end)

I think what you’re saying is that the hitbox is located in a slightly different place than expected.

To solve it, you just need to add weld and change cframe of hitbox to “hrp.CFrame * CFrame.new(0,0,-2)”:

local Special = script.Parent
Special.OnServerEvent:Connect(function(player)

	local hum = player.Character.Humanoid
	local hrp = player.Character.HumanoidRootPart
	local Animator = hum:WaitForChild("Animator")
	local SpecialAnim = script.Parent.Animation
	local animation = Animator:LoadAnimation(SpecialAnim)
	animation:Play()
	print("Animation ended")
	hum.WalkSpeed = 16

	local HitBox = Instance.new("Part")
	HitBox.CFrame = hrp.CFrame  * CFrame.new(0,0,-2)
	HitBox.Size = Vector3.new(5,5,5)
	HitBox.Name = "HitBoxPart"
	HitBox.Parent = game.Workspace
	HitBox.Transparency = 0.5
	HitBox.BrickColor = BrickColor.Red()
	HitBox.CanCollide = false
	HitBox.Anchored = false
        HitBox.Massless = true
	
	local weld = Instance.new("WeldConstraint")
	weld.Parent = hrp
	weld.Part0 = hrp
	weld.Part1 = HitBox

	HitBox.Touched:Connect(function(otherPart)
		local otherHum = otherPart.Parent:FindFirstChild("Humanoid")
		if otherHum then
			if hum then
				if otherPart.Parent.Name == player.Name then
					return
				end
			end
			otherHum:TakeDamage(100)
		end
	end)
	game.Debris:AddItem(HitBox,1.3)
	game.Debris:AddItem(weld,1.3)

end)
1 Like

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