PlayerHitbox not working

local player = game.Players.LocalPlayer
local plr = player.Character
local hitbox = Instance.new("Part")
hitbox.Anchored = true
hitbox.CanCollide = false
hitbox.Name = "PlayerHealthHitbox"
hitbox.Color = Color3.new(1, 0, 0)
hitbox.Transparency = 0.6
hitbox.Parent = plr
if player:WaitForChild("leaderstats").Equipped.Value == 1 then
	hitbox.Size = Vector3.new(4.5, 5.75, 3)
end
while wait() do
	local plr = player.Character
	local x = plr.HumanoidRootPart.Position.X
	local y = plr.HumanoidRootPart.Position.Y
	local z = plr.HumanoidRootPart.Position.Z
	local x2 = plr.HumanoidRootPart.Orientation.X
	local y2 = plr.HumanoidRootPart.Orientation.Y
	local z2 = plr.HumanoidRootPart.Orientation.Z
	hitbox.Position = Vector3.new(x, y, z)
	hitbox.Orientation = Vector3.new(x2, y2, z2)
end

I doesn’t spawn for some reason

Instead of using a while wait loop, weld the part to the player.

Code:

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()

local hitbox = Instance.new("Part")
hitbox.CanCollide = false
hitbox.Name = "PlayerHealthHitbox"
hitbox.Color = Color3.new(1, 0, 0)
hitbox.Transparency = 0.6
hitbox.Parent = character

if player:WaitForChild("leaderstats").Equipped.Value == 1 then
	hitbox.Size = Vector3.new(4.5, 5.75, 3)
end

local weld = Instance.new("WeldConstraint")
weld.Part0 = hitbox
weld.Part1 = character:WaitForChild("HumanoidRootPart")
weld.Parent = hitbox