I’m pretty sure what she meant to say was, based on your post, you wanted to make a “Smart Nextbot AI,” and you want it to be more complex than the usual Nextbots you might’ve seen before or even used before. But on the other hand, she’s not sure what’s the “Smart” level is for you. It may also seems like you don’t even know the basics on scripting, as you don’t even know how to use pathfinding and raycasting to detect players, yet you are looking to create “Smart AI.”
But worry not, I’ll try to help you as best as possible.
So first off, I’ll start with what’s a raycast.
Basicaly, raycast is just like shooting lasers in front of you until it hits something. In this case, we want it to detect players.
local NextBot = script.Parent
local RaycastParams = RaycastParams.new()
Now, we don’t want the laser to just detect nextbots as well right? Let’s say all the nextbots you made are placed in one folder in a workspace. So we just do,
RaycastParams.FilterDescendantsInstances = {workspace.Nextbots} -- Assuming this is where your nextbots are stored, you can also add other stuff in here
RaycastParams.FilterType = Enum.RaycastFilterType.Exclude
Alright, now to actually start with the raycast, we will use, for example, the nextbot’s torso (or the part that you put the decal in) and shoot the laser from there.
local Torso = NextBot.Torso -- Assuming your nextbot has a torso or a part that contains the decal
local direction = head.CFrame.LookVector * 20 -- How long the laser shoots based off where he is facing (20 studs)
local origin = Torso.Position -- Getting the origin position of the nextbot
local result = workspace:Raycast(origin, direction, RaycastParams) -- Using the origin of the laser, direction of where it goes, and the target, which excludes workspace.Nextbots as mentioned previously
if result then -- If it hits
local hitPart = result.Instance
local character = hitPart and hitPart.Parent -- Assuming we just hit a player
local humanoid = character and character:FindFirstChild("Humanoid")
if humanoid then -- Check if the result of the raycast has a Humanoid
print("Player detected:", character.Name) -- Print for debugging
-- You can trigger chase, attack, or alert behavior here
end
end
For starters, I recommend using Humanoid:MoveTo to make the nextbots chase the player, until you managed to get it to work. Once you are able to make a fully functional nextbot system, then you can proceed to learn on the usage of PathfindingService.