You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
Making a tower defense game with a friend and we are making a tower that makes the zombie take damage -
What is the issue? Include screenshots / videos if possible!
The script works fine when the wait is something low (in this case .3) but when you change it to a larger number like 10, it checks if a zombie is in the radius every 10 seconds instead of having a cooldown of 10 seconds -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Tried adding a Debounce but got infinite yield and also tried moving the wait down but got the same problem
(It was very hard wording this so any help is very much appreciated)
local detected = false
local TOWER_RAD = script.Parent.Detection_Radius
while wait() do
local obj_List = TOWER_RAD:GetTouchingParts()
for _, v in pairs(obj_List) do
obj_List = TOWER_RAD:GetTouchingParts()
if v.Name == "zombie" then
detected = true
while v:WaitForChild("health").Value > 0 and table.find(obj_List, v) do
wait(0.3)
v:WaitForChild("health").Value -= 1
obj_List = TOWER_RAD:GetTouchingParts()
end
end
end
if detected == true then
print("Zombie Detected")
end
detected = false
end