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

I made a sword spawn, It respawns twice and then the script stops working. What's wrong?

bin = script.Parent

ItemName = "Darkheart" 
WaitTime = 20 


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)

1 comment

0

I dont know if it matters but i think making the first f in findFirstChild uppercase might fix it

1 answer

Check the comments below, they will help you understand what happened

bin = script.Parent

ItemName = "Darkheart" 
WaitTime = 20 


Item = bin:FindFirstChild(ItemName) -- add a capital F to all :FindFirstChild() s
backup = Item:Clone() -- add a capital C to all :Clone() s

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

debounce = false
local function onTaken(prop)
     if debounce then return end 
     debounce = true
     if bin:FindFirstChild(ItemName) == nil then
          coroutine.wrap(function()
               wait(WaitTime)
               regen() -- regenerate tool
               debounce = false
          end)()
     end
end


Item.Changed:Connect(onTaken) -- RBXScriptSignal:connect is deprecated, use RBXScriptSignal:Connect

Hope this works! If this does work for you, please mark this as one! Thats all, Metatable out!

2 comments

0

The sword only spawns 3 times though.

0

Like it now spawns 3 times and poof! No more.

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