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

Why Does My Regen Button Not Remove The Old Object?

Asked by 8 years ago

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?

1 answer

Log in to vote
0
Answered by 8 years ago

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)
0
I will test this. Also, Config was a Configuration. Winseven4lyf 30 — 8y
0
It still doesn't remove the old one. Sorry. Winseven4lyf 30 — 8y
0
Instead of doing wait(config) just do like wait(3) also the backup:Clone() the C needs a capital ScriptFusion 210 — 8y
Ad

Answer this question