I am attempting to make a minion that will attacking a tower . This is what i have trying

local Target = script.Parent
while true do
   workspace.Minion1.Humanoid:MoveTo(Target.Position)
	wait()
	end
script.Parent.Touched:Connect(function()
	script.Parent.Value.Value = script.Parent.Value.Value - 5
	if script.Parent.Value.Value == 0 then
		script.Parent:Destroy()
          	
	   end
   end)

The part will not get destroyed but when i use this script it work

local Target = script.Parent
while true do
 workspace.Minion1.Humanoid:MoveTo(Target.Position)
wait()
script.Parent.Touched:Connect(function()
	script.Parent.Value.Value = script.Parent.Value.Value - 5
	if script.Parent.Value.Value == 0 then
		script.Parent:Destroy()
          	
	  end
     end)
end

Just asking why it won't working with the first script

3 comments

0

try putting end in the first script below the 'end)' or somewhere in the bottom

0

Indent your script properly

0

In the first script, the end on line 5 closes an infinite while loop, so everything after that is unreachable code