Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I repeat this script PERMANENTLY?

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

✓ Accepted answer

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)

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

This discussion is preserved as it was. New answers, comments, and votes are closed.