Hi there, i'm pretty new to scripting, and i've been dabbling around with this script to try and increase local NoticeDistance to 300 whenever the humanoid is below full health. My changes are on line 10 and 44, and the script works perfectly fine before that. My ultimate goal with this is to try and get the humanoid to aggro at an increased distance whenever it takes damage. Any help would be greatly appreciated.
--[[ By: Brutez. ]]-- -- Edited by hulabee local Bob=script.Parent; local BobHumanoid=Bob:FindFirstChild('Humanoid'); local BobHumanoidRootPart = Bob:FindFirstChild('HumanoidRootPart'); local TheySeeHimKissingDoors=BobHumanoidRootPart:FindFirstChild("BobWhisper"); local DaggerSwingsound=BobHumanoidRootPart:FindFirstChild("DaggerSound"); local SwingDagger=BobHumanoid:LoadAnimation(Bob:FindFirstChild('Slash')); local AttackDebounce=false; function takedamage() local NoticeDistance = 300 wait(300) end while wait(0)do if Bob and BobHumanoidRootPart and TheySeeHimKissingDoors and not TheySeeHimKissingDoors.IsPlaying then TheySeeHimKissingDoors:Play(); end; if Bob and BobHumanoid and not BobHumanoid.AutoJumpEnabled then BobHumanoid.AutoJumpEnabled=true; end; if Bob and BobHumanoid and not BobHumanoid.AutoRotate then BobHumanoid.AutoRotate=true; end; if Bob and BobHumanoid and BobHumanoid.PlatformStand then BobHumanoid.PlatformStand=false; end; if Bob and BobHumanoid and BobHumanoid.Sit then BobHumanoid.Sit=false; end; if Bob and BobHumanoid then BobHumanoid.JumpPower=50; BobHumanoid.WalkSpeed=13; end; if Bob and Bob:FindFirstChild("Head")and Bob:FindFirstChild("Torso")and BobHumanoid and BobHumanoid.Health>0.001 then local NoticeDistance=60; for _,TargetModel in pairs(game:GetService("Workspace"):GetChildren())do if TargetModel.className=="Model"and TargetModel~=Bob and TargetModel.Name ~= "gay" and TargetModel:FindFirstChild("Torso")and TargetModel:FindFirstChild("Head")then local TargetPart=TargetModel:FindFirstChild("Torso") local FoundHumanoid; for _,Child in pairs(TargetModel:GetChildren())do if Child.ClassName=="Humanoid"then FoundHumanoid=Child; end if BobHumanoid.Health ~= BobHumanoid.MaxHealth then takedamage() else end end if TargetModel and TargetPart and FoundHumanoid and FoundHumanoid.Health>0.001 and Bob and Bob:FindFirstChild("Torso")and(TargetPart.Position-Bob:FindFirstChild("Torso").Position).magnitude<NoticeDistance then if TargetModel and TargetPart and FoundHumanoid and FoundHumanoid.Health>0.001 and FoundHumanoid.Jump then BobHumanoid.Jump=true; end; NoticeDistance=(TargetPart.Position-Bob:FindFirstChild("Torso").Position).magnitude; BobHumanoid:MoveTo(TargetPart.Position+(TargetPart.Position-Bob:FindFirstChild("Torso").Position).unit*2,Game:GetService("Workspace"):FindFirstChild("Terrain")); end; if TargetModel and TargetPart and FoundHumanoid and FoundHumanoid.Health>0.001 and Bob and Bob:FindFirstChild("Torso")and(TargetPart.Position-Bob:FindFirstChild("Torso").Position).magnitude<6 and not AttackDebounce then delay(1,function()AttackDebounce=false;end); AttackDebounce=true; FoundHumanoid:TakeDamage(20+math.random()*0.5); BobHumanoidRootPart:FindFirstChild("DaggerSound").Pitch=1+math.random()*0.1; BobHumanoidRootPart:FindFirstChild("DaggerSound"):Play(); SwingDagger:Play(); end; else local JumpChance=math.random(1,3500); local RandomWalk=math.random(1,15000); if Bob and BobHumanoid and JumpChance==1 then BobHumanoid.Jump=true; end; if Bob and BobHumanoid and RandomWalk==1 then BobHumanoid:MoveTo(game:GetService("Workspace"):FindFirstChild("Terrain").Position+Vector3.new(math.random(-2048,2048),0,math.random(-2048,2048)),Game:GetService("Workspace"):FindFirstChild("Terrain")); wait(math.random (1,2)) RandomWalk=0 end; end; end; end; end; --[[ By: Brutez. ]]--