You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? I want to make an AI attack on any amount of cores.
-
What is the issue? This script is not changing the defense value.
-
What solutions have you tried so far? I tried debugging by putting print statements (Shown in code) and nothing is printed to the console until I delete all the cores. When I do this happens:
an endless amount of errors.
Here is my code
local hrp = script.Parent.Parent.HumanoidRootPart -- Humanoid Root Part
local hum = script.Parent.Parent.Humanoid
local pathservice = game:GetService("PathfindingService")
local params = {
AgentRadius = 2.5,
AgentHeight = 4.5,
AgentCanJump = false
}
local path = pathservice:CreatePath(params)
function getNewDes()
local closest = math.huge
local closestObj = nil
for _, obj in pairs(workspace:GetDescendants()) do
if obj.Name:lower():find("core") and obj:IsA("Part") then
if (obj.Position - hrp.Position).Magnitude < closest then
closestObj = obj
closest = (closestObj.Position - hrp.Position).Magnitude
end
end
end
return closestObj
end
function move()
local lastwaypoint = false
function zombieStuck()
local position1 = hrp.Position.Magnitude
wait(1)
local position2 = hrp.Position.Magnitude
local deltaPosition = (math.abs(position1 - position2))
if deltaPosition < 1 then
path:Destroy()
lastwaypoint = true
wait()
for _, I in pairs(game.Workspace.Waypoints:GetDescendants()) do
I:Destroy()
end
script.bool.Value = true
hum:MoveTo(hrp.Position)
wait()
move()
end
end
path:ComputeAsync(hrp.Position, getNewDes().Position)
path.Blocked:Connect(function()
lastwaypoint = true
for _, I in pairs(game.Workspace.Waypoints:GetDescendants()) do
I:Destroy()
end
script.bool.Value = true
move()
end)
local waypoints = path:GetWaypoints()
for _, waypoint in pairs(waypoints) do
local part = Instance.new("Part")
part.Shape = "Ball"
part.Material = "Neon"
part.Size = Vector3.new(0.6, 0.6, 0.6)
part.Position = waypoint.Position
part.Anchored = true
part.CanCollide = false
part.Parent = game.Workspace.Waypoints
end
for _, waypoint in pairs(waypoints) do
if waypoints[#waypoints] == waypoint then
lastwaypoint = true
end
if lastwaypoint == true then
break
end
-- Move zombie to the next waypoint
hum:MoveTo(waypoint.Position)
if lastwaypoint == true then
break
end
-- Wait until zombie has reached the waypoint before continuing
hum.MoveToFinished:Wait()
if lastwaypoint == true then
break
end
end
repeat
zombieStuck()
wait(1)
until las
while wait() do
if lastwaypoint == true then
for _, I in pairs(game.Workspace.Waypoints:GetDescendants()) do
I:Destroy()
end
script.bool.Value = true
break
end
end
end
local count = 0
for _,v in pairs(game.Workspace.Cores:GetChildren()) do
count = count + 1
end
print(count)
local count2 = 0
repeat
wait()
count2 = count2 + 1
move()
repeat
wait()
until script.bool.Value == true
local part = getNewDes()
local Defense = part.Defense.Value
print('1')
repeat
print('2')
wait(.5)
Defense = Defense - script.Parent.Parent.Attack.Value
until Defense <= 0
print('3')
while wait() do
print('4')
if Defense <= 0 then
print('5')
part:Destroy()
break
end
end
until count2 == count
All help is appreciated!!!