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

How can I make an onbject removed on touch then reappear after 90 seconds?

Asked by 6 years ago

So far I managed to make the object become removed once touched, but I can't manage to have the parent of the script reappear successfully. I would like the parent to reappear after 90 seconds of being removed from the workspace. Any help?

script.Parent.Touched:connect(function()
    script.Parent:Destroy();
end)
0
Accidentally said this on my answer also but, please accept my answer if it helped you out. cmgtotalyawesome 1418 — 6y
0
I'd be glad to. How can I do that for you? Hiremetobuildforyou 6 — 6y
0
Side note: I couldn't quite seem to get the script to work eithe. Hiremetobuildforyou 6 — 6y

1 answer

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

You can't actually make the part come back into the workspace unless you are talking about a completely new part. When you use the Destroy() you are completely removing it from your game until the server restarts. If you are talking about a completely new part, you would need to put the script somewhere else because all of the children of the part would also be destroyed. I myself would just change the parent of the part and change it back after 90 seconds. That would look something like this:

debounce = false

script.Parent.Touched:Connect(function()
    if not debounce then
        debounce = true
        script.Parent = game.ServerStorage
        wait(90)
        script.Parent = workspace
        debounce = false
    end
end)

Also, you should no longer be using :connect (talking about the lowercase "c"). That has been deprecated meaning it will no longer work in a later update, as a result, you should use ":Connect", with an uppercase "c". Hope I helped you out.

-cmgtotalyawesome

EDIT: If you were unsure of what the debounce did, it is just a way to keep the function from running over and over again, making it take longer than 90 seconds to put the part back, and also to avoid errors from the function.

0
I can't tell you how much I appreciate this. I have such a mental block when it comes to getting this stuff. Thanks pal! Hiremetobuildforyou 6 — 6y
0
No problem, please accept my answer if I helped cmgtotalyawesome 1418 — 6y
0
I'm wondering why what you wrote me doesnt work. I tested the script on a basic brick, had my character touch it on a test run, and it wont seem to run properly. From what I can tell, whet you wrote seems to make sense. Is there something I could be doing wrong? Hiremetobuildforyou 6 — 6y
0
Is the part inside of the brick? cmgtotalyawesome 1418 — 6y
View all comments (4 more)
0
If it is and the script doesn’t work then please revoke the accepting of this answer, no points were deserved if that is the case. cmgtotalyawesome 1418 — 6y
0
If by part you mean script, then yes. I put the script inside the brick. Would you mind just taking a second look at the script? I think you certainly deserve the points! There must just be one funny, little error. If you don't have the chance, thanks anyway! Hiremetobuildforyou 6 — 6y
0
Yeah I’ll look over it again cmgtotalyawesome 1418 — 6y
0
Would you mind posting the script you have here? Even if it is copy and pasted i would like to see please cmgtotalyawesome 1418 — 6y
Ad

Answer this question