So I was tired of older regen buttons that had a debounce coded, BUT they regened themselves too, which broke the debounce. So I took this code:
model = script.Parent.Parent
messageText = "Regen"
message = Instance.new("Message")
message.Text = messageText
backup = model:clone()
enabled = true
function regenerate()
message.Parent = game.Workspace
model:remove()
wait(2)
model = backup:clone()
model.Parent = game.Workspace
model:makeJoints()
message.Parent = nil
script.Disabled = true
script.Parent.BrickColor = BrickColor.new("Black")
wait(10)
script.Parent.BrickColor = BrickColor.new("Bright violet")
script.Disabled = false
end
function onHit(hit)
if (hit.Parent:FindFirstChild("Humanoid") ~= nil) and enabled then
regenerate()
end
end
script.Parent.Touched:connect(onHit)
And made this:
local config = script.Parent.Config
model = script.Parent.Parent.RegenModel
backup = model:clone()
debounce = false
model:Destroy()
script.Parent.Touched:connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if hit.Parent.Humanoid.Health > 0 then
if debounce == false then
debounce = true
model:Destroy()
local newmodel = backup:clone()
newmodel.Parent = script.Parent.Parent
newmodel:makeJoints()
script.Parent.BrickColor = config.DisabledColour.Value
wait(config.Delay.Value)
script.Parent.BrickColor = config.EnabledColour.Value
debounce = false
end
end
end
end)
It's supposed to regen a model called "RegenModel", but my problem is that it wouldn't remove the old object. I want to make two versions, one that KEEPS the old one [Tick], and one that DOSEN'T KEEP the old one. Why does it not work?

3 comments
I will test this. Also, Config was a Configuration.
It still doesn't remove the old one. Sorry.
Instead of doing wait(config) just do like wait(3) also the backup:Clone() the C needs a capital