Basically, I want to make my tower spawn a thing to attack enemies, like Military Base and Crook Boss from TDS. I have no idea how to do this. Here’s my function. Tell me if you need a certain part of the script. btw, it attacks and is supposed to spawn at the same time, so more like crook boss
function tower.Attack(newTower, player)
local config = newTower.Config
local target = tower.FindTarget(newTower, config.Range.Value, config.TargetMode.Value)
if target ~= nil and target:FindFirstChild("Humanoid") then
AnimateEvent:FireAllClients(newTower, "Attack", target)
if target then
local targetCFrame = CFrame.lookAt(newTower.HumanoidRootPart.Position, target.HumanoidRootPart.Position)
newTower.HumanoidRootPart.BodyGyro.CFrame = targetCFrame
end
damage(target, config)
abilities(newTower, config, target, player)
task.wait(config.Cooldown.Value)
end
task.wait(0.05)
if newTower and newTower.Parent then
tower.Attack(newTower, player)
end
end
Can you maybe be specific or provide a video / image of what your trying to do. I don’t entirely understand what your trying to do, and it would be nice to have more details / Visuals for what your trying to do.
Now you have cloned it and it was spawned in, this means you can have multiple at the same time and manage them too
spawnedthing is the new spawned item which you want to use.
thing is the original item that you want to spawn in
ok, i’ll keep that to remember, but also, how would it function? I want to put it inside the attack function, but it has a seperate cooldown, so it isn’t supposed to spawn when it attacks.
local function clone()
local itemToClone =
itemtoClone -- make this the item you want to clone
local newItem = itemToClone:Clone()
newItem.Parent = tower -- This is now the spawned item
end
Now run this function whenever you want clone the item
So I have this, but the wait(1) is interrupting the rest of the script in the attack function. How would I stop this?
if config.OriginalTower.Value == "tower" then
if config.SpawnCooldown.Value <= 0 then
SpawnUnit(newTower)
else
wait(1)
config.SpawnCooldown.Value -= 1
end
end
I haven’t yet come across a time where I am in need of this but I did some studying and this is what you can do:
local action = coroutine.create(function()
--Here put the function in where you clone the turret
end)
coroutine.resume(action) --This runs the co-routine which runs while the rest of the script is running, even with waits
--The rest of the script can go anywhere
This should hopefully work.
What you want to do is when you want to spawn unit, you put it into this coroutine and it should do it while the rest of the script is running
I’m not sure if this is what you want but (If not you can just change it):
local clone = coroutine.create(function()
if config.OriginalTower.Value == "tower" then
if config.SpawnCooldown.Value <= 0 then
SpawnUnit(newTower)
else
wait(1)
config.SpawnCooldown.Value -= 1
end
end
end)
coroutine.resume(clone) --When you want to check if you can clone the turret
I mean it works, but when the tower isnt attacking, the spawning goes like 3x speed. Probably because its in a function that runs infinitely when the tower is spawned.
It works, just one last problem, the usual tower cooldown is interrupting the spawn. I have a sollution in mind, but it makes the script extremely messy.
wait(config.Cooldown.Value / 10)
coroutine.resume(spawnUnit) --When you want to check if you can clone the turret
wait(config.Cooldown.Value / 10)
coroutine.resume(spawnUnit) --When you want to check if you can clone the turret
wait(config.Cooldown.Value / 10)
coroutine.resume(spawnUnit) --When you want to check if you can clone the turret
wait(config.Cooldown.Value / 10)
coroutine.resume(spawnUnit) --When you want to check if you can clone the turret
wait(config.Cooldown.Value / 10)
coroutine.resume(spawnUnit) --When you want to check if you can clone the turret
wait(config.Cooldown.Value / 10)
coroutine.resume(spawnUnit) --When you want to check if you can clone the turret
wait(config.Cooldown.Value / 10)
coroutine.resume(spawnUnit) --When you want to check if you can clone the turret
wait(config.Cooldown.Value / 10)
coroutine.resume(spawnUnit) --When you want to check if you can clone the turret
wait(config.Cooldown.Value / 10)
coroutine.resume(spawnUnit) --When you want to check if you can clone the turret
wait(config.Cooldown.Value / 10)
coroutine.resume(spawnUnit) --When you want to check if you can clone the turret