✓ Accepted answer
For this, you need to use a technique called debounce. The reason it's spawning multiple times is because every instant the player touches the object, the event is fired again and again. With debounce, you tell the part that it can only be touched once every couple seconds. The basics of debounce work as follows:
1: Create a boolean variable and set it to true
2: On the Touched event, check if the boolean is set to true
3: If it's set to true, set it to false and run the code
4: Wait a few seconds, then set it to true again
Here's your code, with debounce:
local part = script.Parent
local BeheadedRocketeer = game.Lighting.BeheadedRocketeer
local debounce = true
part.Touched:connect(function()
if debounce == true then
debounce = false
local Enemy = BeheadedRocketeer:Clone()
wait(1)
Enemy.Parent = Workspace
wait(3)
debounce = true
end
end)
1 comment
Why the heck was this down voted? I got the script correct.