Script timeout: exhausted allowed execution time

I have no idea about how is this happening.Hope that someone can tell me whats wrong with it and the way to fix it.

Or I need other script that can instead this.

while wait() do

local Start = game.ReplicatedStorage:WaitForChild("Ingame")

if Start.Value == false then
	local Player = 0
	
	for i,v in pairs(game.Players:GetChildren()) do
		Player = i
	end
	
	if Player > 1 then
		print("Yes")
		game.ReplicatedStorage.Game:Fire()
		Start.Value = true
	end
end

end

Script timeout: exhausted allowed execution time

BindableEvent script:

game.ReplicatedStorage.Game.Event:Connect(function()
print(“Yes”)
local Point1 = workspace.Spawnpoint1
local Point2 = workspace.Spawnpoint2

local Team = game:GetService("Teams")
local RedTeam = Team.RedTeam
local BlueTeam = Team.BlueTeam

local Starting = true

local team = 0
for i,v in pairs(game.Players:GetChildren()) do
	if team == 0 then
		print(v)
		v.Team = RedTeam
		team = 1
	else
		print(v)
		v.Team = BlueTeam
		team = 0
	end
end

repeat
	local RedTeam2 = 0
	local BlueTeam2 = 0
	
	for i,v in pairs(game.Players:GetChildren()) do
		if v.Team == RedTeam then
			RedTeam2 = RedTeam2 + 1
		elseif v.Team == BlueTeam then
			BlueTeam2 = BlueTeam2 + 1
		end
	end

	if RedTeam2 == 0 then
		game.ReplicatedStorage.End:Fire("Blue")
		Starting = false
		print("end")
	end
	if BlueTeam2 == 0 then
		game.ReplicatedStorage.End:Fire("Red")
		Starting = false
		print("end")
	end
	
until Starting == false

end)

game.ReplicatedStorage.End.Event:Connect(function()
print(“End”)
local Ingame = game.ReplicatedStorage.Ingame

local Teams = game:GetChildren("Teams")
local WaitingTeam = Teams.WaitingTeam

for _,v in pairs(game.Players:GetChildren()) do
	v.Team = WaitingTeam
end

wait(10)
Ingame.Value = true

end)

1 Like

What does game.ReplicatedStorage.Game:Fire() trigger?

You can also just do

if #game.Players:GetPlayers() > 1 then

But that wouldn’t cause the issue.

2 Likes

game.ReplicatedStorage.Game:Fire() will tigger a bindableevent that inside the ReplicatedStorage

You should add a delay because it will be running forever without stopping.

wait(0.1)

I tried it before but it still not work

I assume you used it in the loop. Replace

wait() 

with

wait(0.1)

So

while wait(0.1) do

What’s the code in the BindableEvent? It’s probably an issue there. That or may need to set the Value of Start to true before you fire the BindableEvent

More specifically, what does the code handling the event do? If the called code doesn’t yield, then the scheduler will wait until that code is finished before resuming here.

It’s highly likely that you are doing too many expensive operations without any yielding in that event handler.

Why don’t you use an event isntead of a loop?

local Start = game.ReplicatedStorage.InGame

Start.Changed:Connect(function ()
      if Start.Value == false then
            -- do stuff
      end
end)
3 Likes

wait() by itself is 1/33rd of a second, if you want to use the fastest increment, then:

while script do
 GetService("RunService").Heartbeat:Wait()
end

EDIT:
plus you shouldnt really use wait() since it waits excessively

1 Like

basically saying the while loop is too fast that it crashed the script, make the wait be like wait(0.0001)

try

local RunService = game:GetService('RunService')


-- run service will never break, unless your performance broke
RunService.Heartbeat:Connect(function()
local Start = game.ReplicatedStorage:WaitForChild("Ingame")

if Start.Value == false then
	local Player = 0
	
	for i,v in pairs(game.Players:GetChildren()) do
		Player = i
	end
	
	if Player > 1 then
		print("Yes")
		game.ReplicatedStorage.Game:Fire()
		Start.Value = true
	end
end
end)

I tried it but it still not work

Please show us the Bindable event code, the issue is either there or you need to change the Value of Start before firing

I place out the script that the BindableEvent will Firing to