Im OriginalDevelops, Im scripting a machine that player clicked and then it spawn a npc, then after a seconds the npc will automatic dead and be removed from the workspace, then the machine will be automatic refresh! This is my script ( normal script not local ) :
local ClickDetector = script.Parent.Detector
local part = script.Parent
local debounce = false
local NPCSpawn = script.Parent.Parent.SpawnPart
local NPC = game.ServerStorage.NPCs.Noob
local newMachine = game.ServerStorage.SpawnMachine
ClickDetector.MouseClick:Connect(function()
if not debounce then
debounce = true
local cloneNoob = NPC:Clone()
cloneNoob.Name = "Noob"
cloneNoob.Parent = NPCSpawn
part.SurfaceGui.TextLabel.Text = "Cooldown..."
part.Color = Color3.fromRGB(255,0,0)
wait(30)
part.SurfaceGui.TextLabel.Text = "Spawn"
part.Color = Color3.fromRGB(0,255,0)
cloneNoob.Humanoid.Health = 0
wait(10)
cloneNoob:Destroy()
print("Cooldown Completed!")
local cloneMachine = newMachine:Clone()
cloneMachine.Name = "SpawnMachine"
cloneMachine.Parent = workspace
print("New Machine Has Been Spawned!")
wait(0.001)
part.Parent:Destroy()
print("Old Machine Has Been Destroyed!")
end
end)
The issue is, all the machine is still working good but the machine can only be refresh once then the machine automatic disappered! The upper code still run, the npc still automatic get destroyed but the machine didnt get clone! That mean the upper code work infinity but the down code only worked once! Can anyone help me with this?

2 comments
Do you ever set debounce to false? If not try setting debounce to false after line 30.
When I set that, the noob not being destroy or kill and the machine being cooldown forever