Script timeout: exhausted allowed execution time How to fix error?
Asked by
3 years ago Edited 3 years ago
So basically I am cloning an NPC 10 times, the script
01 | local val = game.ReplicatedStorage.numberval.Value |
05 | game.ReplicatedStorage.bacteria:Clone() |
06 | game.ReplicatedStorage.bacteria:Clone().Parent = workspace |
07 | game.ReplicatedStorage.bacteria:Clone().HumanoidRootPart.Position = Vector 3. new(math.random(- 315.026 , - 268.827 ),- 148.634 , 2.76 ) |
08 | print ( "spawned 1wave" ) |
14 | game.ReplicatedStorage.bacteria:Clone() |
15 | game.ReplicatedStorage.bacteria:Clone().Parent = workspace |
16 | game.ReplicatedStorage.bacteria:Clone().HumanoidRootPart.Position = Vector 3. new(math.random(- 315.026 , - 268.827 ),- 148.634 , 2.76 ) |
17 | print ( "spawned 2wave" ) |
22 | game.ReplicatedStorage.bacteria:Clone() |
23 | game.ReplicatedStorage.bacteria:Clone().Parent = workspace |
24 | game.ReplicatedStorage.bacteria:Clone().HumanoidRootPart.Position = Vector 3. new(math.random(- 315.026 , - 268.827 ),- 148.634 , 2.76 ) |
25 | print ( "spawned 3wave" ) |
30 | game.ReplicatedStorage.bacteria:Clone() |
31 | game.ReplicatedStorage.bacteria:Clone().Parent = workspace |
32 | game.ReplicatedStorage.bacteria:Clone().HumanoidRootPart.Position = Vector 3. new(math.random(- 315.026 , - 268.827 ),- 148.634 , 2.76 ) |
33 | print ( "spawned 4wave" ) |
37 | for i,v in pairs (game.Workspace:GetChildren()) do |
38 | if v.Name = = "bacteria" and v.Humanoid then |
40 | print ( "removed waste....." ) |
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,
04 | if script.Parent.Humanoid.Health < = 0 then |
05 | game.ReplicatedStorage.numberval.Value = game.ReplicatedStorage.numberval.Value + 1 |
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