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?
Line 3 says :
backup = model:Clone()
And line 14:
local newmodel = backup:Clone()--Why clone it twice?
As I said, why clone it twice?
I think this script should work.
local config = script.Parent.Config--Is this an integer value/intValue? You should just do a number here eg: local config = 5 or whatever. model = script.Parent.Parent.RegenModel backup = model 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)