Weld Constraints Bug When Attacking

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to be able to weld myself to an enemy and destroy the weld after 0.2 seconds and the enemy will stay infront of me

  2. What is the issue? Include screenshots / videos if possible!
    the enemy will teleport backwards after destroying the weld

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have tried motor6D, network ownership, and client sided welds

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
Heres my code:

			if v ~= nil then
				for i,p in ipairs(HitVFX:GetDescendants()) do
					if p:IsA("ParticleEmitter") then
						p:Emit(p:GetAttribute("EmitCount"))
					end
				end
				print(v.Parent)
				local weld = Instance.new("WeldConstraint", RootPart)
				weld.Part0 = RootPart
				weld.Part1 = v.Parent.HumanoidRootPart
				local vel = Instance.new("BodyVelocity", v.Parent.Torso)
				vel.MaxForce = Vector3.new(1,1,1) * 1000000;
				vel.Parent = v.Parent.Torso
				vel.Name  =  "SmallMoveVel"
				vel.Velocity = Vector3.new(1,1,1) * Character.HumanoidRootPart.CFrame.LookVector * 50
				game.Debris:AddItem(vel, 0.2)
				wait(0.2)
				weld:Destroy()
				--RagDoll.EnableRagdoll(v.Parent, 1)
				v.Parent.Humanoid:TakeDamage(Damage)
				wait(0.2)
				for i,d in pairs(v.Parent:GetDescendants()) do
					if d:IsA("BasePart") or d:IsA("MeshPart") then	
						d:SetNetworkOwner(game.Players:GetPlayerFromCharacter(v.Parent))
						d.Massless = false
					end
				end
				
			else
				for i,p in ipairs(HitVFX:GetDescendants()) do
					if p:IsA("ParticleEmitter") then
						p:Emit(p:GetAttribute("EmitCount"))
					end
				end
				print(v)
				local vel = Instance.new("BodyVelocity", Torso)
				vel.MaxForce = Vector3.new(1,1,1) * 1000000;
				vel.Parent = Torso
				vel.Name  =  "SmallMoveVel"
				vel.Velocity = Vector3.new(1,1,1) * Character.HumanoidRootPart.CFrame.LookVector * 50
				game.Debris:AddItem(vel, 0.2)
			end
		end)

Heres a video demo

1 Like

for anyone wondering this is how i fixed it

anim:GetMarkerReachedSignal("hit"):Connect(function()
			if v then
				-- Emit particles
				for _, p in ipairs(HitVFX:GetDescendants()) do
					if p:IsA("ParticleEmitter") then
						p:Emit(p:GetAttribute("EmitCount"))
					end
				end
				-- Print information
				print(v.Parent)
				local Weld = Instance.new("Motor6D") --This weld is what makes both characters near each other and move along side each other
				Weld.Name = "GrabWeld"
				Weld.Parent = RootPart
				Weld.Part0 = RootPart
				Weld.Part1 = v.Parent.HumanoidRootPart
				Weld.C1 = CFrame.Angles(0, math.rad(180), 0) * CFrame.new(0, 0, 3.5)
				game.Debris:AddItem(Weld, 0.2)
				-- Create BodyVelocity to apply force
				local vel = Instance.new("BodyVelocity", v.Parent.HumanoidRootPart)
				vel.MaxForce = Vector3.new(1,1,1) * 1000000
				vel.Velocity = Character.HumanoidRootPart.CFrame.LookVector * 75
				vel.Parent = v.Parent.HumanoidRootPart
				vel.Name = "SmallMoveVel"
				game.Debris:AddItem(vel, 0.4)
				-- Destroy AlignPosition after a short delay
				task.wait(0.2)
				RagDoll.EnableRagdoll(v.Parent, 1)
				-- Apply damage to the enemy
				v.Parent.Humanoid:TakeDamage(Damage)
				-- Set network owner and mass properties for all parts of the enemy
				if game.Players:GetPlayerFromCharacter(v.Parent) then
					for _, part in ipairs(v.Parent:GetDescendants()) do
						if part:IsA("BasePart") or part:IsA("MeshPart") then	
							part:SetNetworkOwner(game.Players:GetPlayerFromCharacter(v.Parent))
							part.Massless = false
						end
					end
				end
			else
				-- Emit particles
				for _, p in ipairs(HitVFX:GetDescendants()) do
					if p:IsA("ParticleEmitter") then
						p:Emit(p:GetAttribute("EmitCount"))
					end
				end
				-- Print information
				print(v)
				-- Create BodyVelocity for self (attacker)
				local vel = Instance.new("BodyVelocity", Torso)
				vel.MaxForce = Vector3.new(1,1,1) * 1000000
				vel.Parent = Torso
				vel.Name = "SmallMoveVel"
				vel.Velocity = Character.HumanoidRootPart.CFrame.LookVector * 50
				game.Debris:AddItem(vel, 0.2)
			end
		end)```

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