Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to prevent this from mass cloning?

Asked by 10 years ago

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

Log in to vote
1
Answered by
hiccup111 231 Moderation Voter
10 years ago

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)
0
Alright, thank you! :D TheRings0fSaturn 28 — 10y
0
Error: AI can spawn more enemies, and I want them to be able to spawn only once. TheRings0fSaturn 28 — 10y
0
So, this script is in other AI? Just remove this script from them. hiccup111 231 — 10y
Ad

Answer this question