How to weld 2 parts together?

I need help welding 2 parts together, a part(hitbox) and the humanoidroot part

3 Likes

You should be spawning the hitbox, positioning it, and then welding it. This seems overly complicated.

1 Like

first of all doesn’t a while true loop crash your game second of all why did you define every single XYZ of position and orientation third of all did you ever continue the coroutine wrap or does it work differently

2 Likes

I need it to run while the animation is running

can you explain why it isn’t spawning?

i cant read the code

1 Like

and there isnt enough code eutger

1 Like

how? its not even that hard to read

idk when its even being called

local rp = game.ReplicatedStorage
local PunchValues = rp.PunchValues
local recoil = PunchValues.Recoil
local punchCount = PunchValues.PunchCount
local moveCount = PunchValues.MoveCount
recoil.Value = 0
moveCount.Value = 1
local function Punch(player)
	print("dqfq")
	if recoil.Value == 1 then
		return
	end
	recoil.Value = 1
	if player.leaderstats.Equipped.Value == 1 then
		if moveCount.Value == 1 then
			local punchAnimation = player.Character.Humanoid.Animator:LoadAnimation(script.BrawlerRightPunch)
			punchAnimation:Play()
			player.Character.Humanoid.WalkSpeed = 8
			player.Character.Humanoid.JumpHeight = 0
			punchAnimation.KeyframeReached:Connect(function(keyframeName)	
				if keyframeName ~= "Damage" then
					return
				end
				local hitbox = Instance.new("Part")
				local x = player.Character.HumanoidRootPart.Position.X 
				local y = player.Character.HumanoidRootPart.Position.Y + 0.5
				local z = player.Character.HumanoidRootPart.Position.Z 
				local x2 = player.Character.HumanoidRootPart.Orientation.X
				local y2 = player.Character.HumanoidRootPart.Orientation.Y - 90
				local z2 = player.Character.HumanoidRootPart.Orientation.Z
				hitbox.Size = Vector3.new(3, 1, 2)
				hitbox.Position = Vector3.new(x, y, z)
				hitbox.Orientation = Vector3.new(x2, y2, z2)
				hitbox.CanCollide = false
				hitbox.Anchored = true
				hitbox.Transparency = 0.8
				hitbox.Color = Color3.new(1, 0, 0)
				hitbox.Parent = player.Character
				coroutine.wrap(function()
					while wait() do
						local x = player.Character.HumanoidRootPart.Position.X 
						local y = player.Character.HumanoidRootPart.Position.Y + 0.5
						local z = player.Character.HumanoidRootPart.Position.Z 
						local x2 = player.Character.HumanoidRootPart.Orientation.X
						local y2 = player.Character.HumanoidRootPart.Orientation.Y - 90
						local z2 = player.Character.HumanoidRootPart.Orientation.Z
						hitbox.Position = Vector3.new(x, y, z)
						hitbox.Orientation = Vector3.new(x2, y2, z2)
					end
				end)
				
				local rightTouched = player.Character.RightLowerArm.Touched:connect(function(hit)
					if hit.Name == "Hitbox" and punchCount.Value == 0 then 
						print("L")
						punchCount.Value = 1
						hit.Parent.Humanoid.Health -= 5
					end
				end)

				local leftTouched = player.Character.RightUpperArm.Touched:connect(function(hit)
					if hit.Name == "Hitbox" and punchCount.Value == 0 then 
						print("U")
						punchCount.Value = 1
						hit.Parent.Humanoid.Health -= 5
					end
				end)

				task.wait(0.2)
				rightTouched:Disconnect()
				leftTouched:Disconnect()
				hitbox:Destroy()
			end)
		elseif moveCount.Value == 2 then
			local punchAnimation = player.Character.Humanoid.Animator:LoadAnimation(script.BrawlerLeftPunch)
			punchAnimation:Play()
			player.Character.Humanoid.WalkSpeed = 8
			player.Character.Humanoid.JumpHeight = 0
			punchAnimation.KeyframeReached:Connect(function(keyframeName)	
				if keyframeName ~= "Damage" then
					return
				end

				local rightTouched = player.Character.LeftLowerArm.Touched:connect(function(hit)
					if hit.Name == "Hitbox" and punchCount.Value == 0 then 
						print("L")
						punchCount.Value = 1
						hit.Parent.Humanoid.Health -= 5
					end
				end)

				local leftTouched = player.Character.LeftUpperArm.Touched:connect(function(hit)
					if hit.Name == "Hitbox" and punchCount.Value == 0 then 
						print("U")
						punchCount.Value = 1
						hit.Parent.Humanoid.Health -= 5
					end
				end)

				task.wait(0.2)
				rightTouched:Disconnect()
				leftTouched:Disconnect()
			end)
		end
	end
	wait(0.5)
	moveCount.Value += 1
	recoil.Value = 0
	punchCount.Value = 0
	player.Character.Humanoid.WalkSpeed = 16
	player.Character.Humanoid.JumpHeight = 7
	if moveCount.Value == 3 then
		moveCount.Value = 1
	end
end
local function Brawler1(player)
	if recoil.Value == 1 then
		return
	end
	moveCount.Value = 101
	recoil.Value = 1
	if moveCount.Value == 101 then
		local punchAnimation = player.Character.Humanoid.Animator:LoadAnimation(script.BrawlerMove1)
		punchAnimation:Play()
		punchAnimation.KeyframeReached:Connect(function(keyframeName)	
			if keyframeName ~= "Damage" then
				return
			end

			local rightTouched = player.Character.RightLowerArm.Touched:connect(function(hit)
				if hit.Name == "Hitbox" and punchCount.Value == 0 then 
					print("L")
					punchCount.Value = 1
					hit.Parent.Humanoid.Health -= 25
				end
			end)

			local leftTouched = player.Character.RightUpperArm.Touched:connect(function(hit)
				if hit.Name == "Hitbox" and punchCount.Value == 0 then 
					print("U")
					punchCount.Value = 1
					hit.Parent.Humanoid.Health -= 25
				end
			end)

			task.wait(0.2)
			rightTouched:Disconnect()
			leftTouched:Disconnect()
			moveCount.Value = 1
		end)
	end
	wait(1)
	recoil.Value = 0
	punchCount.Value = 0
	print(moveCount.Value)
end
rp.Punch.OnServerEvent:Connect(Punch)
rp.Brawler1.OnServerEvent:Connect(Brawler1)

yea idk how to fix im not expierendced in this stuff ma n sorruy

you’ll most definitely have to add a wait in there if this part is going to be following the plr around I would suggest using renderstep or heartbeat (whatever floats your boat)

Also does this print?

Yeah, it’s really bad, giving me an eyesore to read, however it could be optimised heavily from what I can manage to read.

It’s as Katrist said, you should be making the hitbox, then you position it, and then if you want the hitbox to stay infront of the player you just need to weld it to the HumanoidRootPart or wherever you want. Making a while true loop to update the position seems too complicated and you are just making the code longer.

You would only need a loop for hit detection. Just weld it like the others said. Also calm down on the posts lol.

i was literally editing the title ._.

how do you weld the hitbox to the humanoidrootpart?

I said that 19 hours ago…

Anyways lol you can weld the hitbox by using weld constraints.

local weld = Instance.new(“WeldConstraint”)
weld.Part0 = rootPart
weld.Part1 = hitbox
weld.Parent = hitbox

Create the hitbox, weld it, then just handle hit detection.

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