What do you want to achieve?
Make the AI walk to random waypoints.
What is the issue?
The issue is the output keep giving the " What do you want to achieve?
You know the “creator” thing to know who it who that killed the person in Classic Sword,I’m putting it on my sword but I’m having an error with a function related to the above…
What is the issue?
The problem is that it tells me attempt to index nil with ‘GetChildren’
.
It said that the issue is in this line:
function Bot:patrol()
local waypoints = self.killerWaypoints:GetChildren()
local randomPoint = math.random(1, #waypoints)
Bot:moveTo(waypoints[randomPoint])
end
This is the full script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local CollectionService = game:GetService("CollectionService")
local PhysicsService = game:GetService("PhysicsService")
local PathfindingService = game:GetService("PathfindingService")
local Debris = game:GetService("Debris")
local Bot = {}
Bot.__index = Bot
function Bot:new(model)
local killer = setmetatable({},Bot)
-- childs
killer.model = model
killer.humanoid = model:WaitForChild("Humanoid")
killer.rootPart = model:WaitForChild("HumanoidRootPart")
-- configs
killer.sounds = ReplicatedStorage:WaitForChild("Sounds")
killer.animations = ReplicatedStorage:WaitForChild("Animations")
killer.name = model.Name
killer.killerWaypoints = model.Parent:WaitForChild("KillerWaypoints")
killer.humanoid.WalkSpeed = 15.5
Bot:setPhysics()
Bot:animate()
local firstPoint = killer.killerWaypoints:FindFirstChild("First")
if not firstPoint then
firstPoint = killer.rootPart.Position + Vector3.new(0,0,10)
end
killer.humanoid:MoveTo(firstPoint.Position)
killer.humanoid.MoveToFinished:Wait()
end
function Bot:setPhysics()
local success, err = pcall(function()
self.model.PrimaryPart:SetNetworkOwner(nil)
end)
if not success then
warn("Killer:", err)
end
end
function Bot:animate()
end
function Bot:getPath(destination)
local pathParams = {
["AgentHeight"] = 4,
["AgentRadius"] = 7,
["AgentCanJump"] = false
}
local path = PathfindingService:CreatePath(pathParams)
path:ComputeAsync(self.rootPart.Position - destination.Position)
return path
end
function Bot:canSeeTarget(target)
local origin = self.rootPart.Position
local direction = (target.HumanoidRootPart.Positon - origin).unit * 80
local rayParams = RaycastParams.new()
rayParams.FilterDescendantsInstances = {self.model, self.model.Parent:FindFirstChild("ClickDoors")}
rayParams.FilterType = Enum.RaycastFilterType.Blacklist
local hit = workspace:Raycast(origin, direction, rayParams)
if hit then
if hit:IsDescendantOf(target) then
return true
end
else
return false
end
end
function Bot:findTarget()
local players = game.Players:GetPlayers()
local nearestTarget = nil
local maxDistance = 50
for index, player in pairs(players) do
local character = player.Character or player.CharacterAdded:Wait()
if character then
local target = character
local distance = (self.rootPart.Position - target.HumanoidRootPart.Position).magnitude
if distance < maxDistance and Bot:canSeeTarget(target) then
maxDistance = distance
nearestTarget = target
end
end
end
return nearestTarget
end
function Bot:chaseTarget(target)
local distance = (target.HumanoidRootPart.Position - self.rootPart.Position).magnitude
if distance > 2 then
self.humanoid:MoveTo(target.HumanoidRootPart.Position)
else
print("Kill")
target.Humanoid.Health = 0
end
end
local function displayPath(waypoints)
local color = BrickColor.Random()
for index, waypoint in pairs(waypoints) do
local part = Instance.new("Part")
part.BrickColor = color
part.Anchored = true
part.CanCollide = false
part.Size = Vector3.new(1,1,1)
part.Position = waypoint.Position
part.Parent = workspace
local Debris = game:GetService("Debris")
Debris:AddItem(part, 6)
end
end
function Bot:moveTo(destination)
local path = Bot:getPath(destination)
if path.Status == Enum.PathStatus.Success then
for index, waypoint in pairs(path:GetWaypoints()) do
local target = Bot:findTarget()
if target and target.Humanoid.Health > 0 then
Bot:chaseTarget(target)
break
else
displayPath(path:GetWaypoints())
self.humanoid:MoveTo(waypoint.Position)
self.humanoid.MoveToFinished:Wait()
end
end
else
self.humanoid:MoveTo(destination.Position - (self.rootPart.CFrame.LookVector * 10))
end
end
function Bot:patrol()
local waypoints = self.killerWaypoints:GetChildren()
local randomPoint = math.random(1, #waypoints)
Bot:moveTo(waypoints[randomPoint])
end
return Bot
Other script that seems to be needed:
local CollectionService = game:GetService("CollectionService")
local Bot = require(script.Bot)
local Players =require(script.Player)
CollectionService:GetInstanceAddedSignal("KillerBot"):Connect(function(model)
Bot:new(model)
while wait(1) do
Bot:patrol()
end
end)
CollectionService:GetInstanceAddedSignal("KillerPlayer"):Connect(function(model)
end)
local bot = script.Dummy:Clone()
bot.Parent = workspace.Map
if bot then
CollectionService:AddTag(bot, "KillerBot")
bot:SetPrimaryPartCFrame(workspace.Map.KillerSpawn.CFrame)
end
What solutions have you tried so far?
I tried to read the script again and again to find where is the error come from but still blank and idk what to do with it pls help