Look, im making a tower defense game.

but when i try to make the magnitude part (to make the towers have a range and look at enemies)

It wont print the distance. take a look and please help me D:

local tower = workspace.Tower

local enabled = false

while true do
	wait()
	
	if enabled == false then
		enabled = true
		
		local attack = false
		
		for i, v in pairs(workspace.Enemies:GetChildren()) do
			local distance = (v.Position - script.Parent.Position).magnitude
			if distance < 15 and attack == false then
				print("ok")
			end
		end
	end
end

i mean, the enemy spawns but the tower dont get the distance, no errors or prints. and when its not duplicated (in the folder) it checks and print

1 comment

0

If your enemies in folder are cloned as used, the function wont work - it only detects once cause the function doesnt work again. look at line 8- if there is no other way to set enabled as false,they wont start detect except enemies already spawn on the folder workspace.Enemies