My script waits a few extra seconds and then disables? I am trying to make a some enemies stop following me by making their distance to me 0, I am using a value for this. here is my script:
Enemy Script
local larm = script.Parent:FindFirstChild("HumanoidRootPart") local rarm = script.Parent:FindFirstChild("HumanoidRootPart") function findNearestTorso(pos) local list = game.Workspace:children() local torso = nil local dist = script.Value.Value local temp = nil local human = nil local temp2 = nil for x = 1, #list do temp2 = list[x] if (temp2.className == "Model") and (temp2 ~= script.Parent) then temp = temp2:findFirstChild("HumanoidRootPart") human = temp2:findFirstChild("Humanoid") if (temp ~= nil) and (human ~= nil) and (human.Health > 0) then if (temp.Position - pos).magnitude < dist then torso = temp dist = (temp.Position - pos).magnitude end end end end return torso end while true do wait(1) local target = findNearestTorso(script.Parent.HumanoidRootPart.Position) if target ~= nil then script.Parent.Zombie:MoveTo(target.Position, target) end end
Value Changing Script
local checkpoint = game.Workspace.Checkpoints.Checkpoint1 local connection = checkpoint.Touched:Connect(function(hit) if game.Players:GetPlayerFromCharacter(hit.Parent) then game.Workspace.Dark.Script.Value.Value = 35 wait(15) script.Parent.CanCollide = false checkpoint.CanCollide = false script.Parent.BrickColor = BrickColor.new("Lime green") checkpoint.BrickColor = BrickColor.new("Lime green") game.Workspace.Checkpoints.Checkpoint2.BrickColor = BrickColor.new("Lime green") game.Workspace.Dark.Script.Value.Value = 0 game.connection:Disconnect() end end)