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

Script timeout: exhausted allowed execution time How to fix error?

Asked by
ym5a 52
3 years ago
Edited 3 years ago

So basically I am cloning an NPC 10 times, the script

01local val = game.ReplicatedStorage.numberval.Value
02 
03 
04for i = 1,10 do
05    game.ReplicatedStorage.bacteria:Clone()
06    game.ReplicatedStorage.bacteria:Clone().Parent = workspace
07    game.ReplicatedStorage.bacteria:Clone().HumanoidRootPart.Position = Vector3.new(math.random(-315.026, -268.827),-148.634, 2.76)
08    print("spawned 1wave")
09    wait()
10end
11 
12if val >= 10 then
13    for i = 1,10 do
14        game.ReplicatedStorage.bacteria:Clone()
15        game.ReplicatedStorage.bacteria:Clone().Parent = workspace
View all 43 lines...

the first block of code is the important part, this error started when I put the small script below inside the NPC that is being cloned,

01--the script is in the model the npc that is being cloned , the npc is stored in replicated storage
02wait(1)
03while true do --where the stack ends
04if script.Parent.Humanoid.Health <= 0 then
05    game.ReplicatedStorage.numberval.Value = game.ReplicatedStorage.numberval.Value + 1
06wait()
07        print("added 1")
08    end
09end
10--this script is where the error occurs, but only occurs once the script above this is enabled, even though the script is enabled in the NPC that is being cloned in replicatedstorage
11, so it happens when its cloned

I've tried messing with settings when I enabled the script to clone the NPC it practically crashes roblox I'm trying to make it that once the value = 0 it stops spawning the npcs Before this I made a script practically like this but I ended up removing it. If you have any other ways of trying to perform what I have attempted please do so in the comments

1 answer

Log in to vote
2
Answered by 3 years ago
Edited 3 years ago

While you have added a wait() in the while loop, you placed the wait() in the conditional statement and forgot to consider what happens if the Humanoid's health is above 0. If the Humanoid's health is above 0 it will ignore everything inside the conditional statement and continue looping.

1wait(1)
2while true do
3    if script.Parent.Humanoid.Health <= 0 then
4        game.ReplicatedStorage.numberval.Value = game.ReplicatedStorage.numberval.Value + 1
5        wait()
6        print("added 1")
7    end
8end

Simply moving the wait() out of the conditional statement, as done below, should fix it:

1wait(1)
2while true do
3    if script.Parent.Humanoid.Health <= 0 then
4        game.ReplicatedStorage.numberval.Value = game.ReplicatedStorage.numberval.Value + 1
5        print("added 1")
6    end
7    wait()
8end
0
Thanks, but can you fix the first long script, but how do I make the first script keep checking the val number without spawning anymore npcs ym5a 52 — 3y
Ad

Answer this question