So I want to make the Robot stop lagging kind of or at least try to(I’m also new to Scripting by the way)
So this is the script but please ignore the other stuff unless if it’s the problem:robloxapp-20210802-0024101.wmv (2.8 MB)
local ReplicatedStorage = game:GetService(“ReplicatedStorage”).Robot
local RunService = game:GetService(“RunService”)
RunService.Stepped:Connect(function() – Runs this script forever
local KadenogiPlayer = game.Players:FindFirstChild("Kadenogi")
local Kadenogi = game.Workspace:FindFirstChild("Kadenogi")
local Robot = game.Workspace:FindFirstChild("Robot")
local MaxDistanceT = 200 -- T means Teleport
local MaxDistanceTF = 50 -- TF means Too Far
local MaxDistanceF = 20 -- F means Far
local MaxDistanceC = 10 -- C means Closest
-- Checks if Kadenogi(Which is my User) is in the game. If it is, then the Robot will be moved into Workspace
if KadenogiPlayer then
wait(1)
ReplicatedStorage.Parent = game.Workspace
end
-- Checks if Kadenogi(Which is my User) is in the game. If it is not, then the Robot will be moved back into ReplicatedStorage
if KadenogiPlayer == nil then
wait(1)
ReplicatedStorage.Parent = game.ReplicatedStorage
end
-- Makes the Robot follow only Kadenogi(Which is my User)
if Kadenogi and Robot then
local PathParam = {
["AgentRadius"] = 3,
["AgentHeight"] = 5,
["AgentCanJump"] = true
}
local Destination = Kadenogi.HumanoidRootPart.Position + Vector3.new(-3.5,0,4.5)
local RobotWRP = Robot.HumanoidRootPart.Position
if Kadenogi and Robot then
local function WalkTo(Destination)
local Path = game:GetService("PathfindingService"):CreatePath(PathParam)
Path:ComputeAsync(RobotWRP, Destination)
if Path.Status == Enum.PathStatus.Success then
for index, Waypoint in pairs(Path:GetWaypoints()) do
Robot.Humanoid:MoveTo(Waypoint.Position)
Robot.Humanoid.MoveToFinished:Wait()
end
end
end
WalkTo(Destination)
end
end
-- Makes Robot change Speed if Robot is too far away, and returns back to normal Speed if the Robot is close enough
if Kadenogi and Robot then
if (Kadenogi.HumanoidRootPart.Position - Robot.HumanoidRootPart.Position).magnitude >= MaxDistanceTF then
Robot.Humanoid.WalkSpeed = 50
end
if (Kadenogi.HumanoidRootPart.Position - Robot.HumanoidRootPart.Position).magnitude >= MaxDistanceF then
Robot.Humanoid.WalkSpeed = 23
end
if (Kadenogi.HumanoidRootPart.Position - Robot.HumanoidRootPart.Position).magnitude <= MaxDistanceC then
Robot.Humanoid.WalkSpeed = 19
end
end
-- Makes Robot Teleport if Kadenogi(Which is my User) and the Robot way too far away
if Kadenogi and Robot then
if (Kadenogi.HumanoidRootPart.Position - Robot.HumanoidRootPart.Position).magnitude >= MaxDistanceT then
Robot.HumanoidRootPart.CFrame = Kadenogi.HumanoidRootPart.CFrame + Vector3.new(-3.5,0,4.5)
end
end
end)