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!
make a “first” targetting for my td game -
What is the issue? Include screenshots / videos if possible!
the targetting just doesnt work -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
i tried to look for some on devforum
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
my current code:
local towerStats = script.Parent.Stats
local enemyFolder = workspace.Enemies
function FindTarget(): Model
local target = nil
local bestWaypoint = nil
local bestDistance = nil
for _, v in enemyFolder:GetChildren() do
local distanceToWaypoint = (v.PrimaryPart.Position - workspace.Map.Path.Waypoints["Waypoint"..v.MovingTo.Value].Position).Magnitude
if not bestWaypoint or v.MovingTo.Value >= bestWaypoint then
if bestWaypoint then
bestDistance = nil
end
bestWaypoint = v.MovingTo.Value
if not bestDistance or distanceToWaypoint < bestDistance then
bestDistance = distanceToWaypoint
target = v
print(target.Name)
target.Torso.Color = Color3.new(255,0,0)
end
end
end
return target
end
while true do
local targret = FindTarget()
if targret then
targret.Humanoid:TakeDamage(towerStats.Damage.Value)
end
wait(towerStats.Firerate.Value)
end
(i think its very clear i used gnomecode’s video)