Make model move to humanoid

so i tried to make a model move to human but it’s just stuck in the middle,

here’s my script:

	function(TargetPlayer)
	local dirc = char.HumanoidRootPart.CFrame
	bone.Bone.Anchored = true
	bone.Bone.Locked = true
	bone.Bone.CanCollide = false
	local hate = false
	for i= 0,1, 0.1 do
	wait()
	local ee = bone:Clone()
	ee.Parent = workspace
	ee.Bone.Position = Vector3.new(npcToFind.HumanoidRootPart.Position.X,npcToFind.HumanoidRootPart.Position.Y + 9 , npcToFind.HumanoidRootPart.Position.Z)
	game:GetService("Debris"):AddItem(ee, 2)
	ee.Bone.CFrame = dirc:lerp(ee.Bone.CFrame,0.5)
	hate = false
	if char.Humanoid.Health <= 0 then
		break
	end
	ee.Bone.Touched:Connect(function(d)
	local player = game:GetService("Players"):GetPlayerFromCharacter(d.Parent)
		if hate == false then
		if player then
			player.Character.Humanoid:TakeDamage(2)
			hate = true
		else
			hate = false
		end
		end
	end)
	end
	return 2
end

here what i mean by stuck in middle:

https://gyazo.com/3885c8d1519d108f0a56a5d35941787b
sorry for the not organized code btw

2 Likes

This is probably because dirc:lerp(ee.Bone.CFrame,0.5) only lerps it halfway between the humanoid rootpart and the bone.

Are you trying to make the bone smoothly move to the HRP or move to it instantaneously?

If you want a dynamic and overall smoother effect, try using a Rocket Propulsion. Parent it to the bone that you clone, set its target to your target character, and play around with settings. There’s a TargetReached event for it that you can use to deal damage if and when it comes close enough, and then destroy it.

i don’t want it to follow the player, i want it to shoot the player from where it’s started to where player been when it’s started

i want to make it move smoothly

in that case, you can use the for loop you are already using to move it smoothly, However, you should make a variable for the initial CFrame of the bone, to make it more linear move

For example:

local InitialCfm = ee.Bone.CFrame

for i = 0,1,0.1 do
   wait()
   ee.Bone.CFrame = InitialCfm.lerp(dirc,i)
end

you can also do

dirc:lerp(ee.Bone.CFrame,i)

although if you are doing that, be sure to “reverse the direction” of the for loop, as to not make it go backwards:

local InitialCfm = ee.Bone.CFrame
for i= 1,0, -0.1 do
   ee.Bone.CFrame = dirc:lerp(InitalCfm,i)
   wait()
end
3 Likes

oh yay it works, sorry for long time not replying , i had to do something, anyway i have another question, how i can make it move alittle bit further and not exactly where humanoid is?

1 Like

I too have to apologize for the late response xd

but you simply do this by setting the alpha value of the lerp to a value > 1

For example:

local InitialCfm = ee.Bone.CFrame

for i = 0,1.2,0.1 do
   wait()
   ee.Bone.CFrame = InitialCfm.lerp(dirc,i)
end

In this case, i set the “max alpha” value to 1.2

oh ok, and for the - thing it would be [for i = -2,0,-0.1]?

yes if you want it to go 2x the distance

1 Like