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

How can I repeat this script PERMANENTLY?

Asked by 9 years ago

I am working on a Sword Regen Script, and for some reasons that I don't know, It can only respawn 1 time after taken by a player.

The Outrageous Sword Item Name is correct, but like I said, it can only respawn 1 time.

Here's the script:

bin = script.Parent

ItemName = "Outragousword" -- The name of the item in the stand.
WaitTime = 20 -- The amount of time to wait before regenerating the item.


Item = bin:findFirstChild(ItemName)
backup = Item:clone()

function regen()
    local regen = backup:clone()
    regen.Parent = bin
end

debounce = false
function onTaken(property)
if (debounce == true) then return end
debounce = true
    if (bin:findFirstChild(ItemName) == nil) then
        wait(WaitTime)
        regen()
    end
debounce = false
end


Item.Changed:connect(onTaken)

What am I suppose to add to make the Sword Respawn every time it's been taken by players instead of just once?

2 answers

Log in to vote
4
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
9 years ago

So from what I can tell, you have a model with a script and a sword in it. When the sword is no longer inside that model, you want to wait 20 seconds and then have a clone of the sword reappear.

local sword=script.Parent:WaitForChild("Outragousword")
local new=sword:clone()

script.Parent.ChildRemoved:connect(function(x)
    if x==sword then
        wait(20)
        sword=new:clone()
        sword.Parent=script.Parent
    end
end)
Ad
Log in to vote
-4
Answered by 9 years ago

I'm pretty sure it would be "Outragoussword" Two s's as it is outrageouS Sword

Answer this question