Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Im Trying To Make A Tower Defense Targetting System But It Wont Target Enemies Even In Range?

Asked by 3 years ago

Hello, I Am Trying To Make A Tower Defense Targeting System. All The Code Is Right Allegedly... I am trying to have it when an enemy is in range of the tower. The Tower Will Start Shooting There's Is A Sound In the Gun. But Nothing Plays Or Prints In The Output.

Here is The Code.

local shoot = script.Parent.Humanoid:LoadAnimation(script.Parent.Shoot)
local idle = script.Parent.Humanoid:LoadAnimation(script.Parent.Idle)


idle:Play()

--setup
local curzombies = workspace.Objects.CurZombies
local char = script.Parent
local statistics = script.Parent.Stats

-- main
for i,V in pairs(curzombies:GetChildren()) do
    local distance = (V.HumanoidRootPart.Position - char.HumanoidRootPart.Position).magnitude
    if distance < statistics.Range.Value then
        print("Shooting")
        shoot:Play()
        char.Handle.Attachment.Fire:Play()
        V.Humanoid.Health = V.Humanoid.Health - statistics.Damage.Value
    else
        break
    end
0
It looks like you haven't closed the for loop? jasperagent 43 — 3y
0
thank you. CallMe_Axis 63 — 3y

Answer this question