I keep getting a strange error in the console which appears to be causing huge amounts of lag

I can’t prove scripts right now because I’m not home at the moment, but as soon as I’m able to I’ll provide you with a few scripts

1 Like

UPDATE: I am now able to supply some code that uses PlayerAdded. Here they are:

local function OnPlayerAdded(player)
	if GamePassService:PlayerHasPass(player, GamePassIdObject.Value) then
		local starterGear = WaitForChild(player, 'StarterGear')
		CloneAdminTools(starterGear)
		if player.Character then -- They've already loaded and won't get their StarterGear until next spawn
			local backpack = WaitForChild(player, 'Backpack')
			CloneAdminTools(backpack)
		end
	end
end

That is a script which gives the player a tool they bought using a gamepass, this is one of the few scripts in the game that isn’t created by me.

The next script:

local badgeID = 653725714
local badgeService = game:GetService("BadgeService")
function onEntered(player)
    wait(1)
    if not badgeService:UserHasBadge(player.UserId, badgeID) then
        badgeService:AwardBadge(player.UserId, badgeID)
    end
end
 
game.Players.PlayerAdded:Connect(onEntered)

That script awards a player a badge when they join.
These were the only 2 scripts I could find with PlayerAdded.

Try searching for require.

[30 char]

1 Like

I found in the output that as soon as it happens, there’s an error from the AdminTools script, which is the top one.

1 Like

Here’s some footage of the lag happening:

I think this is the same as another post. CoreGui PlayerRelationship module error

Did you show us all the lines of code in the AdminTools script?

No, here’s the full script. Something to note though, I just noticed a line that said:

game.Workspace.InsertBoard.Parent = game.Lighting

I don’t have something in the workspace named InsertBoard anymore. Could it be something that small causing such a large issue? Here’s the full script:

local function WaitForChild(parent, childName)
	assert(parent, "ERROR: WaitForChild: parent is nil")
	while not parent:FindFirstChild(childName) do parent.ChildAdded:wait() end
	return parent[childName]
end

-----------------
--| Variables |--
-----------------

local GamePassService = game:GetService('GamePassService')
local PlayersService = game:GetService('Players')
local InsertService = game:GetService('InsertService')
local LightingService = game:GetService('Lighting') --TODO: Use new data store service once that exists

local GamePassIdObject = WaitForChild(script, 'GamePassId')
local ToolAssetsToLoad = WaitForChild(script, 'ToolAssetsToLoad')

local AdminTools = LightingService:FindFirstChild('AdminTools')

-----------------
--| Functions |--
-----------------

-- Makes copies of all the admin tools and puts them in target
local function CloneAdminTools(target)
	for _, tool in pairs(AdminTools:GetChildren()) do
		local toolClone = tool:Clone()
		toolClone.Parent = target
	end
end

-- When a player with the game pass joins, give them the admin tools
local function OnPlayerAdded(player)
	if GamePassService:PlayerHasPass(player, GamePassIdObject.Value) then
		local starterGear = WaitForChild(player, 'StarterGear')
		CloneAdminTools(starterGear)
		if player.Character then -- They've already loaded and won't get their StarterGear until next spawn
			local backpack = WaitForChild(player, 'Backpack')
			CloneAdminTools(backpack)
		end
	end
end

--------------------
--| Script Logic |--
--------------------

-- Create AdminTools if it doesn't exist
if not AdminTools then
	AdminTools = Instance.new('Model')
	AdminTools.Name = 'AdminTools'

	-- Load all of the assets in ToolAssetsToLoad and put them in AdminTools
	for _, intObject in pairs(ToolAssetsToLoad:GetChildren()) do
		if intObject and intObject:IsA('IntValue') and intObject.Value then
			local assetModel = InsertService:LoadAsset(intObject.Value)
			if assetModel then
				local asset = assetModel:GetChildren()[1]
				if asset then
					asset.Parent = AdminTools
				end
			end
		end
	end

	AdminTools.Parent = LightingService
end

PlayersService.PlayerAdded:connect(OnPlayerAdded)

from what I know this is a bug. It was supposed to be fixed. Are you on mobile because if yes the bug is still known to be on there.

Do you think it is an backdoor?

[30 char]

Well, we figured out that the error has nothing to do with the lag. It’s coming from the Admin Tools script most likely. I could care less about an error in my output. Thank you for the link though, I’ll check that out once I finish this! :slight_smile:

I don’t think so, I could use a different script for the Admin Tools and make my own.

I’m somewhat convinced that it could have been that one line I removed, but I don’t know.

I don’t see a link. (Extended for 30 chars)

1 Like

Did you fix the issue already?

I’m not sure, I’m gonna update the game in a minute.

Oof, things were looking great until it lagged again. It wasn’t the admin script. I really need help.

Try using the thingy i “made”!

try to send a bug report to Roblox. By now I have no clue what could be causing it. Try reinstalling Roblox studio and Roblox.

1 Like

Depending on how often and from where you call that method, it could potentially be a resource-leak in your game, due to its infinite looping setup.

That is, if somewhere you use this infinite-loop-waiting-for-a-child-object, and the child-object with the wanted childName-value never is added/created, then that method will never return and just use up resources.

Perhaps you should change it to the following code, using call to {instance}:WaitForChild(), and then deal with any errors that may show during gameplay, due to missing child-objects:

local function WaitForChild(parent, childName)
  assert(parent, "ERROR: WaitForChild: parent is nil")
  return parent:WaitForChild(childName, 5) -- 5 seconds timeout (or use a higher timeout seconds if needed.)
end