I have a rig and I want it to follow the player for 20 seconds if it touches the rig’s “circle”. The circle is a big circle that is in the middle of the rig.
Assuming this script is inside of the rig:
local rig = script.Parent
local target = nil
local WalkTime = 20 -- Time in seconds for how long the rig walks for
local Radius = 5 -- The radius of the circle
local circle = Instance.new('Part')
circle.Parent = weld
circle.Size = Vector3.new(Radius*2, Radius*2, Radius*2)
circle.Shape = Enum.ShapeType.Circle
local weld = Instance.new('Weld')
weld.Parent = circle
weld.Part0 = circle
weld.Part1 = rig.HumanoidRootPart -- The main object of the rig
local touched = false
circle.Touched:Connect(function(hit)
if game.Players:GetPlayerFromCharacter(hit.Parent) then
touched = true
target = hit.Parent
local humanoid = rig.Humanoid
humanoid.WalkToPart = target.Torso
task.wait(WalkTime)
humanoid.WalkToPart = nil
end
end)
Tell me if this helps
The rig doesn’t move or walk
Insert a new rig using the Avatar tab at the top of the screen, click “Rig Builder”, and insert an new rig of any type into the Workspace. Then insert a script and paste the code into that new script.
Try that and see if it works
Yhe rig with the script is r15
I see.
Try this:
local rig = script.Parent
local target = nil
local WalkTime = 20 -- Time in seconds for how long the rig walks for
local Radius = 5 -- The radius of the circle
local circle = Instance.new('Part')
circle.Parent = weld
circle.Size = Vector3.new(Radius*2, Radius*2, Radius*2)
circle.Shape = Enum.ShapeType.Circle
local weld = Instance.new('Weld')
weld.Parent = circle
weld.Part0 = circle
weld.Part1 = rig.HumanoidRootPart -- The main object of the rig
local touched = false
circle.Touched:Connect(function(hit)
if game.Players:GetPlayerFromCharacter(hit.Parent) then
touched = true
target = hit.Parent
local humanoid = rig.Humanoid
humanoid.WalkToPart = target.HumanoidRootPart
task.wait(WalkTime)
humanoid.WalkToPart = nil
end
end)
local or regular script???
Just a regular script
The script will run on the server for all players, otherwise put it in a LocalScript
its still not working for some reason
it says that Enum is not a part of circle
local rig = script.Parent
local target = nil
local WalkTime = 20 -- Time in seconds for how long the rig walks for
local Radius = 5 -- The radius of the circle
local circle = Instance.new('Part')
circle.Parent = weld
circle.Size = Vector3.new(Radius*2, Radius*2, Radius*2)
circle.Shape = Enum.PartType.Circle
local weld = Instance.new('Weld')
weld.Parent = circle
weld.Part0 = circle
weld.Part1 = rig.HumanoidRootPart -- The main object of the rig
local touched = false
circle.Touched:Connect(function(hit)
if game.Players:GetPlayerFromCharacter(hit.Parent) then
touched = true
target = hit.Parent
local humanoid = rig.Humanoid
humanoid.WalkToPart = target.HumanoidRootPart
task.wait(WalkTime)
humanoid.WalkToPart = nil
end
end)
Now it should work
Circle is not a valid member of “Enum.PartType”
Change it to Enum.PartType.Ball
it still doesn’t walk for some reason
This script should work.
Put the code in a Server Script and parent it to the rig that will follow the player. Make sure the RunContext of the script is set to Client. You will also set the NetworkOwner of the rootpart to nil so it won’t move for other people.
local PathfindingService = game:GetService("PathfindingService")
local PlayersService = game:GetService("Players")
local RunService = game:GetService("RunService")
local Rig = script.Parent
local LocalPLayer = PlayersService.LocalPlayer
local Character = LocalPLayer.Character or LocalPLayer.CharacterAdded:Wait() -- Waits until the character is added before proceeding
local radiusConnection = nil
local FOLLOW_DISTANCE = 7 -- How far the LocalPlayer has to be before following the player's movements
local COPY_DISTANCE = 7 -- How close the LocalPlayer has to be before copying the LocalPlayer's movement
local function FollowPlayer()
local flag = (radiusConnection == nil)
if radiusConnection then
radiusConnection:Disconnect()
end
while wait() do
if flag then
local distance = LocalPLayer:DistanceFromCharacter(Rig.HumanoidRootPart.Position)
if distance < FOLLOW_DISTANCE then
task.spawn(function()
FollowPlayer()
end)
break
end
end
local Path: Path = PathfindingService:CreatePath({AgentCanClimb = true})
Path:ComputeAsync(Rig.HumanoidRootPart.Position, Character.HumanoidRootPart.Position)
if Path.Status ~= Enum.PathStatus.Success then
warn(Path.Status)
Rig:PivotTo(Character.HumanoidRootPart.CFrame)
task.spawn(function()
FollowPlayer()
end)
break
end
local stop = false
local blocked
blocked = Path.Blocked:Connect(function(index)
stop = true
FollowPlayer()
end)
local waypoints = Path:GetWaypoints()
for _, waypoint in ipairs(waypoints) do
if stop then break end
if waypoint.Action == Enum.PathWaypointAction.Jump then
Rig.Humanoid.Jump = true
end
Rig.Humanoid:MoveTo(waypoint.Position)
Rig.Humanoid.MoveToFinished:Wait()
local distance = LocalPLayer:DistanceFromCharacter(Rig.HumanoidRootPart.Position)
if distance < FOLLOW_DISTANCE then
task.spawn(function()
FollowPlayer()
end)
break
end
end
blocked:Disconnect()
if stop then print("stopped") break end
task.spawn(function()
FollowPlayer()
end)
break
end
end
local called = false
radiusConnection = RunService.Heartbeat:Connect(function()
local distance = (Character.HumanoidRootPart.Position - Rig.HumanoidRootPart.Position).Magnitude
if distance > COPY_DISTANCE then return end
if called == true then return end
called = true
task.spawn(function()
FollowPlayer()
end)
end)
You can’t get LocalPlayer in a server script.
You can if you set the RunContext to client.
it doesn’t work for me i dont know why
the walkpoint is set but its not walking for some reason?
local Players = game:GetService(‘Players’)
local Rig = script.Parent
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 hitboxcf = Rig.PrimaryPart.CFrame
local hitboxSize = Vector3.new(20,20,20)
local Target = nil
local PartsInRegion = workspace:GetPartBoundsInBox(hitboxcf,hitboxSize, Params)
while Target == nil do
for i, Parts in ipairs(PartsInRegion) do
if Parts.Parent and Parts.Parent:FindFirstChild("Humanoid") then
if Parts.Parent ~= Rig then
Target = Players:GetPlayerFromCharacter(Parts.Parent)
end
end
end
task.wait()
end
print(Target)