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

Regenerating parts once every 15 seconds?

Asked by 5 years ago
Edited 5 years ago

I am not skilled enough to do something like this so I used someone's free model. This script regenerates parts but there is 2 things I don't like about it. One is that when you touch the block, it regenerates the part every 0.1 second until you get off it. I put a wait before "regenerate()" and it was regenerating parts every 10 seconds which is what I want. However, if the player touches the block 5 times and walks away, it'll regenerate the parts every 10 seconds until it regenerates 5 times because that's how many times the player touched it. How can I make this that once the player touches the block it regenerates all parts and then waits 10 seconds before the player can touch the block again to regenerate?

01model = script.Parent.Parent
02 
03backup = model:clone()
04enabled = true
05 
06function regenerate()
07    model:remove()
08    model = backup:clone()
09    model.Parent = game.Workspace
10    model:makeJoints()
11    script.Disabled = true
12    wait(10)
13    script.Disabled = false
14end
15 
View all 22 lines...

2 answers

Log in to vote
1
Answered by 5 years ago

You disabled the script, and then attempted to re-enable it in the same script. This wouldn't work because the script would be disabled, so it couldn't re-enable itself since it's disabled. Instead use a debounce. Also, I made the variables local and improved some stuff. Try this:

01local model = script.Parent.Parent
02 
03local backup = model:Clone()
04local enabled = true
05 
06local debounce = false
07 
08local function regenerate()
09    if not debounce  then
10        debounce = true
11        model:Destroy()
12        model = backup:Clone()
13        model.Parent = workspace
14        model:MakeJoints()
15        wait(10)
View all 26 lines...
Ad
Log in to vote
0
Answered by 5 years ago

Add a debounce to it, to prevent it from running.

Answer this question