Fix welded part floating off character

I’m trying to weld projectiles to my character and whenever it welds most of the time it floats off of my avatar like this:
image

Here’s my code, how can I fix the position of the projectile so it sticks to the part it touches?

local Debris = game:GetService("Debris")
local pellet:BasePart = script.Parent
local damage = 8

--local maxWalkSpeed = 0

local w

local lastHit = nil

function onTouched(hit:BasePart)

	if hit.Parent.Name ~= "Jeep" then --make goop not stick to cars
		

		if not w then
			w = Instance.new("WeldConstraint", pellet) --stick to ground or whatever hit
			w.Part0 = pellet
			w.Part1 = hit
		end


		pellet.ThrowSound:Play()

		local h= hit.Parent:FindFirstChild("Humanoid") or hit.Parent.Parent:FindFirstChild("Humanoid")

		if h then
			
			if w and lastHit ~= nil and lastHit ~= hit then
				w.Part1 = hit --stick to character if stepped on
			end
			

			pellet.CanTouch = false
			pellet.CanCollide = false
			
			pellet.Parent = h.Parent.Parent
			
			--maxWalkSpeed = h.WalkSpeed
			
			local plr = game.Players:GetPlayerFromCharacter(h.Parent)
			
			if plr then
				plr.Gooped.Value = true
			end

			h:TakeDamage(damage)
			h.WalkSpeed = math.clamp(h.WalkSpeed * 0.85, 3, math.huge)

			pellet.Destroying:Connect(function()
				h.WalkSpeed = math.clamp(h.WalkSpeed * 1.15, 3, math.huge)
				
				if plr and plr.Gooped.Value == true and not h.Parent:FindFirstChild("Goop") then
					print("ungooped")
					plr.Gooped.Value = false
				end
			end)
		end
		
		lastHit = hit
		
	end

end



pellet.Touched:Connect(onTouched)
Debris:AddItem(pellet, 30)


1 Like