"Script timeout: Exhausted allowed execution time" from adding a tag to a model. What?

I am writing some code to display a ScreenGui when I hover over a specific model:

local function checkHoverForSurvivor()
	local target = mouse.Target	
	if not target then return end

	local currentParent = target.Parent
	while currentParent do
		if currentParent:IsA("Model") and currentParent:HasTag("Survivor") then
			local id: StringValue = currentParent:FindFirstChild("ID")
			if not id then continue end

			updateSurvivorDisplay(id.Value)
			survivorDisplay.Enabled = true

			return
		end
		currentParent = currentParent.Parent
	end

	survivorDisplay.Enabled = false
end

RunService.RenderStepped:Connect(checkHoverForSurvivor)

It gives the script timeout error on this line: local id: StringValue = currentParent:FindFirstChild("ID"). The weird part is that it only gives this error (and crashes my Roblox Studio) when I place the Survivor tag on a model. Why would that cause this error? It works completely fine otherwise.

The culprit is the ‘while’ loop. I’d recommend adding a small task.wait() value or use some other method with the script.

1 Like

if not id then continue end is the problem. I think you meant to update the currentParent before moving onto the next loop.

Edit: Replied to wrong person, mb.

2 Likes

I tried that already. Plus, it’s connected to RunService.RenderStepped. It’s mentioned in the post that the only time the error fails is when I add a tag to the models I want to detect. Otherwise, it works without error and without adjusting the code.

Thank you so much! That was the issue.

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