Tower defense finding target but without loop

hi im ctg i need help
im making td system but i wont use loop bc bad performance so i use raycast but problem here is in server side, inside enemy only have Vector3Value so idk how to use raycast with vector3value

1 Like

just use raycasting and implement a vector3? it shouldn’t be that hard if you know how to raycast really. from what I looked up just get the value from the Vector3Value and Implement it into raycast.

i dont use raycast alot tbh, most i like system scripter
but also how i can get value without loop?

thanks for help me, this impossbile bc without part cant cast anything soo i will skip this ig

Honestly, Why bother making the raycast server side if you’re going all in on the client? use a remote function and invoke a random player. That remote function will return “hits” aka the client models it hit via the raycast. And then you can use it on the server

function FindTarget(origin, range)
	local bestTarget = nil
	local bestWaypoint = nil
	local bestDistance = nil
	local bestHealth = nil
	local map = workspace.Map:FindFirstChildOfClass("Folder")
	local Hits  = {}
	local overlapParams = OverlapParams.new()
	overlapParams.FilterType = Enum.RaycastFilterType.Include
	overlapParams.FilterDescendantsInstances = workspace.Enemies:GetChildren()
	for i, part in ipairs(workspace:GetPartBoundsInRadius(origin, range, overlapParams)) do
		table.insert(Hits,part.Parent)
	end
	for i, target in pairs(Hits) do
		local distanceToTarget = (target.PrimaryPart.Position - origin).Magnitude
		if distanceToTarget <= range then
			range = distanceToTarget
			bestTarget = target
		end
	end
	return bestTarget
end
remotefunction.OnClientInvoke = FindTarget

Vector3.Value its an instance value (im guessing) so it’s basically the exact same thing as doing

local vakue = Instance.new("StringValue",enemy)
vakue.Value = "I am DBANDS!"
print(vakue.Value)

as for raycasting its all about origin and direction.
the origin would be the tower and the direction would be a circle mainly,
This a post about raycasting a circle (which would be ur range)

have a good one

How is using raycasting more performant than a loop?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.