Wait() and Attributes

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    Basically I want the script & the parent to delete itself after a certain duration, With the duration having different values, which is set by other scripts.

  2. What is the issue? Include screenshots / videos if possible!
    wait() or task.wait() doesn’t seem to be accepting variables from attributes, note that this is a server script with the duration attribute of script.Parent set to 5. The path’s are working as i have other :Getattribute calls that works perfectly, it’s precisely the “wait()” command that’s not working for me nor, does the task.wait(). Everytime I run the code there is absolutely no delay in the script

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I’ve tried looking at the hub and no one seems to tackle this issue precisely.
    I’ve tried using tonumber() or to string(), I’ve tried directly inserting a value inside the wait() call i.e wait(5) & it works perfectly. It just that when it is a called attribute that the issue arises.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

print("Should Run After "..script.Parent:GetAttribute("Duration").." seconds?")
	local dur = script.Parent:GetAttribute("Duration")
		task.wait(dur)
print("ran")
			game:GetService("Debris"):AddItem(script.Parent,0)
			game:GetService("Debris"):AddItem(script,0)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

2 Likes

What it’s the Duration attribute type?

1 Like

the attribute is set to A Number value

Why can’t you just update it from the script? Why does it have to be an attribute?

I want other scripts to be able to change the duration

What’s the output of the first line?


Also, instead of doing that you can just do script:Destroy()

1 Like

Does it output any errors at all?

1 Like

Having been stuck in this rabbit hole of a bug for 3 hours now, took a step back and realized that part of my code is actually removing my script from it’s supposed parent, finding a nil attribute. Which for some reason doesn’t send a log in the output bar. I suppose that is the issue i’ve been relying on to show up. is this a bug??

Having posted the code, I haven’t added the “print” call to the code, hence why I found the bug after pasting it in my studio. Though prior to posting, It didn’t output any errors when it was not finding the “Duration” in the :GetAttribute(“Duration”) call which I found peculiar

Thanks! I forgot this call existed

Though thinking about it wait(nil) would actually just be wait() which is why this was probably difficult to pinpoint.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.