If you’ve played the game “Plants vs Zombies” before, there are “towers” that can shoot whenever a zombie infront of them.
Plants vs Zombies is a lane-styled tower defense game.
My current code is simply in these steps:
-
Finding the lane the tower is in.
-
Check if the lane is not empty.
-
Get the enemies inside the lane
-
Check if the distance is lower than the range. (flawed)
local laneSelected : Folder = workspace.Enemies[config.LaneDefend.Value] if (#laneSelected:GetChildren() > 0) then for _, enemy : Folder in pairs(laneSelected:GetChildren()) do local Distance = (tower:FindFirstChildOfClass("Model").PrimaryPart.Position - enemy:FindFirstChildOfClass("Model").PrimaryPart.Position).Magnitude if Distance <= config.Range.Value then return true else return false end end else return false end end
My issue is towers would shoot even if an enemy is behind them and would like replace the code with the tiles as a term of range. Any form of help would- well… Help.