Maximum event re-entrancy depth exceeded for ScriptContext.Error // Script timeout: exhausted allowed execution time Server - AssignNpcs:98

The maneuver: player clicks GUI then NPC spawns accordingly

This error kind of came out of nowhere this maneuver has been working perfectly fine for the past few days, but then out of nowhere when I now run the game this error pops up.

The NPC does eventually spawn in accordingly, but that’s after a delay caused by the error.

I tried reversing the changes which I made to scripts of other areas of the game though keep in mind these sets of code were not touched at all, but it was no help this error keeps popping up.

Local script side:

local button = script.Parent
local plr = script.Parent.Parent.Parent.Parent



button.MouseButton1Up:Connect(function()
	
	game.ReplicatedStorage.SoldierButton:FireServer(plr)

	
end)


server script side:

local changeGui = game.ReplicatedStorage:WaitForChild("ChangeGui")
local amountOfMoney = game.ReplicatedStorage:WaitForChild("SendMoney")
local teamRed = game.Teams:FindFirstChild("Red")
local teamBlue = game.Teams:FindFirstChild("Blue")
local teamGreen = game.Teams:FindFirstChild("Green")
local teamBlack = game.Teams:FindFirstChild("Black")
local hCounter1 = 1
local nCounter1 = 1
local hCounter2 = 1
local nCounter2 = 1
local hCounter3 = 1
local nCounter3 = 1
local hCounter4 = 1
local nCounter4 = 1
local redNpcs = game.ReplicatedStorage.Npcs:FindFirstChild("RedUnit")
local BlueNpcs = game.ReplicatedStorage.Npcs:FindFirstChild("BlueUnit")
local GreenNpcs = game.ReplicatedStorage.Npcs:FindFirstChild("GreenUnit")
local BlackNpcs = game.ReplicatedStorage.Npcs:FindFirstChild("BlackUnit")
_G.MoneyR = 600
_G.MoneyB = 600
_G.MoneyG = 100
_G.MoneyBL = 100
game.ReplicatedStorage.SoldierButton.OnServerEvent:Connect(function(plr)


	if plr.Team == teamRed and _G.MoneyR >= 50 then
		_G.MoneyR -= 50
	
		if #workspace.RedNpcs:GetChildren() < 40 then

			local clone = redNpcs:Clone()
			local cloneHumanoid = clone:FindFirstChildWhichIsA("Humanoid")
			clone.Name = "RedUnit" .. tostring(nCounter1)
			cloneHumanoid.Name = "Humanoidr" .. tostring(hCounter1)
			clone.Parent = workspace.RedNpcs
			clone.PrimaryPart.CFrame = workspace.RedCastle.SpawnPoint.CFrame
			hCounter1 += 1
			nCounter1 += 1
		
		end
	
	elseif plr.Team == teamBlue and _G.MoneyB >= 50 then
		_G.MoneyB -= 50
		
		if #workspace.BlueNpcs:GetChildren() < 40 then

			local clone = BlueNpcs:Clone()
			local cloneHumanoid = clone:FindFirstChildWhichIsA("Humanoid")
			clone.Name = "BlueUnit" .. tostring(nCounter2)
			cloneHumanoid.Name = "HumanoidB" .. tostring(hCounter2)
			clone.Parent = workspace.BlueNpcs
			clone.PrimaryPart.CFrame = workspace.BlueCastle.SpawnPoint.CFrame
			hCounter2 += 1
			nCounter2 += 1
		
		end
				
	end
end)

Wow feel hopeless sometimes guys the problem was so simple I just forgot to slide the output problem fixed

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.