How do I make rig move and follow a player

GetPartsBoundsInBox is not a valid member of Workspace “Workspace”

I edited it, copy and paste and try again.

i dont think it does anything in the game

Sorry i forgot to arrange it, here is the actual code:

local Players = game:GetService('Players')

local Rig = script.Parent

local Params = OverlapParams.new()
Params.FilterDescendantsInstances = {workspace}
Params.FilterType = Enum.RaycastFilterType.Include

--//Get hitbox position and size
local hitboxSize = Vector3.new(50,6,50)

local Target = nil
while Target == nil do
	local hitboxcf = Rig.PrimaryPart.CFrame
	local PartsInRegion = workspace:GetPartBoundsInBox(hitboxcf,hitboxSize, Params)

	for i, Parts in ipairs(PartsInRegion) do
		if Parts.Parent and Parts.Parent:FindFirstChild("Humanoid") then
			if Parts.Parent ~= Rig then
				Target = Parts.Parent
			end
		end
	end
	task.wait()
end

print(Target)

Now next to this code, you can add another that moves the humanoid to the target:

while Target and Target:FindFirstChild("Humanoid") and Target.Humanoid.Health > 0 do
	local Root = Target:FindFirstChild("HumanoidRootPart")
	
	if Root then
		local RootPos = Root.Position
		Rig.Humanoid:MoveTo(RootPos, Root)
	end
	task.wait()
end

Now it will walk towards the target until it dies or whatever happens to it, its really simple code nothing too advanced but i think that’s what you were looking for.

Result:

External Media

is there a way to add a delay to it so it doesn’t constantly follow the player

you can add a task.wait(delayTime) on top of the code to delay it

thank you for all your help sir :slight_smile:

no problem! Mark my code as a solution if you want.

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