I’ve been playing around with AI lately so I tried making a little demo with creepers that blow up when you get close to them.
The only problem is that when more then creeper spawns things get weird like creeper not blowing up at all, creeper blows up at random, and they just don’t blow up at all
--local PATH_SERVICE = game:GetService("PathfindingService")
--local PATH = PATH_SERVICE:CreatePath({AgentRadius = 2, AgentHeight = 6,AgentCanJump = true});
local CURRENT_TARGET = nil;
local CREEPER = script.Parent.HumanoidRootPart;
local DEBRIS = game:GetService("Debris")
while wait() do
--Select closet target
for name,player in pairs(game.Players:GetPlayers()) do
player.Character:WaitForChild("HumanoidRootPart")
if CURRENT_TARGET == nil then
CURRENT_TARGET = player;
else
if (CREEPER.Position - player.Character.HumanoidRootPart.Position).Magnitude < (CREEPER.Position - CURRENT_TARGET.Character.HumanoidRootPart.Position).Magnitude then
CURRENT_TARGET = player;
end
end
end
CURRENT_TARGET.Character:WaitForChild("HumanoidRootPart")
script.Parent.Humanoid:MoveTo(CURRENT_TARGET.Character.HumanoidRootPart.Position)
if (CREEPER.Position - CURRENT_TARGET.Character.HumanoidRootPart.Position).Magnitude <= 3 then
CREEPER.Sound:Pause()
wait(3)
local CREEPER = workspace.Creeper.HumanoidRootPart;
local sound = Instance.new("Sound",CREEPER)
sound.SoundId = "rbxassetid://5651511737";
sound.SoundGroup = game.SoundService.SoundGroup;
sound:Play()
local bomb = Instance.new("Explosion",CREEPER)
bomb.Position = CREEPER.Position
bomb.ExplosionType = Enum.ExplosionType.Craters;
wait(.8)
sound:Destroy()
CREEPER.Parent:Destroy()
end
end