Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to prevent this from mass cloning?

It is an enemy spawner script, and I just finished writing it (at the time of me posting this.) It basically just pulls a model from the lighting and inserts it where ever it was in the Workspace where you placed it, but it over clones it. Anyways to prevent this?

local part = script.Parent
local Kamikaze = game.Lighting.Kamikaze

part.Touched:connect(function()
local Enemy = Kamikaze:Clone()
	wait(1)
	Enemy.Parent = Workspace 
	wait(1)

end)

1 answer

✓ Accepted answer

You need what's called a Debounce, because, this will just keep firing and doing the exact same thing whenever it's touched

local part = script.Parent
local Kamikaze = game.Lighting.Kamikaze
local debounce = false

part.Touched:connect(function() if debounce then return end --Check if it's already running

debounce = true	-- This event is running!

local Enemy = Kamikaze:Clone()
    wait(1)
    Enemy.Parent = Workspace 
    wait(1)

debounce = false -- This event has stopped, you can now touch again!

end)

3 comments

0

Alright, thank you! :D

0

Error: AI can spawn more enemies, and I want them to be able to spawn only once.

0

So, this script is in other AI? Just remove this script from them.

This discussion is preserved as it was. New answers, comments, and votes are closed.