Hey guys, just having a small (and probably very dumb!) issue, where I’m unable to make a script destroy itself
Here’s what i’m doing to try to destroy it / prevent it from working
-- In the local script itself
script:Destroy()
script.Disabled = true
Functions:Destroy(script)
while task.wait(.1) do
print("Heheheaw")
end
-- In the module called functions here
function module:Destroy(Object)
Object:Destroy()
end
“Heheheaw” is still being printed every .1 seconds. Does anyone know what mistake i have made here? Please let me know if you do! Thank you for taking the time to read this
sadly, the first option seems to give the same result and the 2nd option is what i wanted to avoid. If i however print the scripts parent in a loop instead of the hehehehaw, the parent is nil as expected
This while loop, is preventing from the code below [calling the module] from running.
I suggest wrapping that loop with a coroutine or a spawn function.
I don’t really mind what i delete it in, but i don’t see why i’d need to do it in a while loop since it’d just need to also still be running constantly
That’s wild. Doesn’t seem like it should work that way does it? XD
--script:Destroy()
--script.Disabled = true
Functions:Destroy(script)
task.wait() -- defer will cancel after first wait..here or once thru loop
while task.wait(.1) do
print("Heheheaw")
end
-- In the module called functions here
function module:Destroy(Object)
-- task.delay will work too.. again after delay time, at next wait after called
task.defer(function()
Object:Destroy()
end)
end
Pretty sure I had a version (that I didn’t save) with task.delay(n, function()... called from the LocalScript that worked if script.Disabled was commented out. That Disable seems to be able to keep parts of the script from working (e.g. keeps the fn in the task.delay from being able to Destroy the script), but it doesn’t kill the while true loop. script:Destroy() called from the LocalScript removed the script from the explorer and presumably set it’s parent to nil (didn’t check), but the loop is entered and keeps on going. Didn’t try this, but can maybe try putting wait between the Functions:Destroy line and the while loop and see if that’s enough for the script:Destroy() to do its thing.