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

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

Asked by 4 years ago
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)

0
I dont know if it matters but i think making the first f in findFirstChild uppercase might fix it super1boom 0 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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!

0
The sword only spawns 3 times though. iIndominusRexi 0 — 4y
0
Like it now spawns 3 times and poof! No more. iIndominusRexi 0 — 4y
Ad

Answer this question