How to force players to be attracted at a part?

Hello people,

Please help me, I am trying to create a Pipe Bomb (Tool), a bit similar to Left 4 Survival on Roblox, and when I throw it, players around the Pipe Bomb will be forced to walk towards it, using lookAt() and look at it, with their HumanoidRootPart CFrame looking at the Pipe Bomb, and if the Pipe Bomb explodes and players are trying to walk towards it, it will just cancel the force walk and the lookAt() and I find that very hard.

I think it might be using:

Magnitude, lookAt() and MoveTo()

I have looked at many posts yet it doesn’t answer my question, and I have also tried to code it but it is very hard.
Please somebody tell me how to achieve this, maybe some posts or basic coding, but I am NOT asking for a whole script.

Please and thank you.


Here is a failed attempt of me trying to do the same effect, basically when you touch the part, you will be “forced” to walk to the target, while your HumanoidRootPart looks at the target, but it just like “locks” my character in place.

local part = script.Parent
local target = game.Workspace.target

part.Touched:Connect(function(hit)
	local humanoid = hit.Parent:FindFirstChild("Humanoid")
	local char = hit.Parent
	local humrp = hit.Parent:FindFirstChild("HumanoidRootPart")
	if (humanoid ~= nil) then	
		humanoid:MoveTo(target.Position)
		local oldhumrp = humrp.CFrame
		while true do
		humrp.CFrame = CFrame.lookAt(humrp.Position, Vector3.new(target.Position.X, humrp.Position.Y, target.Position.Z))
		task.wait()
		end
		humanoid.MoveToFinished:Connect(function() 
			print("We reached the target!")
			humrp.CFrame = oldhumrp
       end)
    end
end)

It might be locking the character because you’re constantly setting its CFrame while it is trying to MoveTo(p). The while loop you create never breaks, which is far worse.

Doesn’t MoveTo already force the player to look at the position? Anyways, there are definitely better ways to do this, though I’m not sure until I try.

P.S. Sorry for the wait. I sure know how it feels!

1 Like