How will I find the first enemy ( kind of like the ones in tower defense games )? I know that I can add a value to the enemies every 0.01 second and get the largest value, however, they all have different walkspeed. Anyone know how to do this? Thanks.
Well, to add onto your idea for putting a value on the enemies;
I suggest that the interval the value is gained in should vary based on walkspeed. The only downside to this is that each interval for each enemy would need to be very precise.
I’m not good at explaining things, but lets say the default speed is 8, and lets also assume that you’ve decided the default interval would be 1. For an enemy that is 25% slower, you’d want set the value to 1.25 seconds, no more no less. Same goes for an enemy with 25% more speed, which would be 0.75 seconds. You would need to use a calculator to determine what speeds and intervals your enemies need, which can get frustrating at times.
I understand that this seems like a vague solution, and I apologize. Unfortunately, that’s probably as simple as it gets.
EDIT: Lag is also an issue! I can imagine that big games like Tower Defense Simulator use long time intervals for default enemies, depending on how fast they spawn. Again, I’m not good at explaining things, but I’ll put this in the simplest terms I can: 30 enemies with 0.01 time interval make fps drop and you single-handedly crash roblox. If your spawn rate for enemies is like 2 seconds per enemy, make the default time interval 2 seconds to minimize lag.
Yeah, lag is also an issue. I’ll try to make the interval to 2 seconds instead of 0.01 seconds. Thanks for your help!
local enemyFolder = workspace.Enemies --Example folder.
local function getFastestEnemy()
local fastestSpeed, fastestEnemy = 0, nil
for _, enemy in ipairs(enemyFolder:GetChildren()) do
if enemy:IsA("Model") then
local enemyRoot = enemy:FindFirstChild("HumanoidRootPart")
local enemySpeed = enemyRoot.AssemblyLinearVelocity
if enemySpeed > fastestSpeed then
fastestSpeed = enemySpeed
fastestEnemy = enemy
end
end
end
return fastestEnemy
end
This function will return the fastest enemy from a folder of enemies.