Error 291 in my game... How do I fix this?

I keep getting an error where the DataModel is deleted while playing my game: Infinite Obby! [ALPHA] - Roblox

I’d like some help figuring this out and resolving the issue. I assume it’s something my code is doing but I have no idea what. I’ve tried disabling scripts here and there, but to minimal success.

At first everything is fine, but then all of a sudden the UI starts glitching and dissappearing, then after a few seconds or minutes it’s all gone. After that the game is fine for a bit, but then you get the ERROR 291 with a screen blur and you get kicked. Here is a video after the UI dissappears.

TLDR: I get error 291, and I tried disabling certain scripts, tested the game and the issue persists. I’d like some pointers as to what functions or coding practices can cause such an issue. Maybe too many DataStore calls? some rate limit issue? Any pointers could help me narrow down to a script and I’ll post it here for some advice.

1 Like

Error 291 appears when your player object is removed from the data model by calling :Destroy() on it. To figure out which script is causing the issue, go to View → Find/Replace All which will open up a window from where you can search for :Destroy() and looking through all the entries to determine where the code is being called from

1 Like

Hey,

So I did check through all my scripts but I don’t delete the player in any script. I knew but I tried to find/replace anyways. I do destroy some things, but they are objects (mostly GUI) since I scripted a GUI or two.

Any other suggestions?

Check again as this is the only reason. Perhaps instead of gui you destroy the player.

Can’t be since the GUI reference is created within the script with an Instance.new and deleted from the same variable.

Although I did discover that I was using :BreakJoints() to kill the player. I’m not testing the game with Health = 0 instead. Along with a disabled camera fix script. Since the UI seems to glitch out before anything happens.

Checked almost all the scripts… disabling a bunch at a time… still no solution.

I’d be down to show the game and scripts to whoever.

You can sent the place file in my DMs, I can check it out and lyk if I found smth

I don’t feel comfortable sending the place itself, but id appreciate any help through a call with screensharing. Feel free to reach out to me in DMs for a call or something.

Check for :ClearAllChildren() and :Remove() too.

Found the issue to be a script inside my ReplicatedFirst. I have no idea how this is causing ERROR 291 (DataModel deleted)… My friend assumes some sort of memory leak or issue caused by something in the script. No idea what it could be.

Any insights would be appreciated!

local player = game:GetService("Players").LocalPlayer
local marketService : MarketplaceService = game:GetService("MarketplaceService")
local gamepassId = 212885695

if not marketService:UserOwnsGamePassAsync(player.UserId, gamepassId) then
	return
end

task.spawn(function()
	while task.wait(2.5) do
		local workspaceParts = workspace:GetDescendants()
		for i = 1, #workspaceParts do
			local currPart : Part = workspaceParts[i]
			if currPart.Name ~= "cheese" or currPart:FindFirstChild("Highlight") then
				continue
			end

			local partHighlight = Instance.new("SelectionBox")
			partHighlight.Parent = currPart
			partHighlight.Adornee = currPart
			partHighlight.Color3 = Color3.fromRGB(0, 255, 136)
			partHighlight.LineThickness = 0.05
		end
	end
end)

What is this script trying to achieve?

There should be a check for if they already have a SelectionBox so it doesn’t make duplicates.

Fixed code:

local player = game:GetService("Players").LocalPlayer
local marketService : MarketplaceService = game:GetService("MarketplaceService")
local gamepassId = 212885695

if not marketService:UserOwnsGamePassAsync(player.UserId, gamepassId) then
	return
end

local selectionBoxes = {}

task.spawn(function()
	while task.wait(2.5) do
		for i, descendant in ipairs(workspace:GetDescendants()) do
			if descendant.Name ~= "cheese" or descendant:FindFirstChild("Highlight") or selectionBoxes[descendant] then
				continue
			end

			local partHighlight = Instance.new("SelectionBox")
			partHighlight.Adornee = descendant
			partHighlight.Color3 = Color3.fromRGB(0, 255, 136)
			partHighlight.LineThickness = 0.05
			partHighlight.Parent = descendant

			selectionBoxes[descendant] = true
		end
	end
end)

Ah, you are right… I assume the game kept adding more and more selection boxes, eventually leading to additional lag on server and client. That was probably causing the error…

EDIT 1: Oh wait I have a check if it already has a high-light… so that can’t be it.

For more context, these are invisible paths called “Cheese” in an obby. The obby repeats itself infinitely. Just a gamepass idea…

Highlights are different from SelectionBox. No clue why you named your variable partHighlight even though you’re creating a SelectionBox.