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

Are you sure it’s because that sit script?
because if it is, I think this script will fix it:

function ontouch(hit)
	 if game.Players:GetPlayerFromCharacter(hit.Parent) then
        local Humanoid = hit.Parent:FindFirstChild("Humanoid")
        if Humanoid then
			Humanoid = hit.Parent:WaitForChild("Humanoid")
			if(Humanoid.Sit == false) then
			Humanoid.Sit = true
			end
        end
	end
end
script.Parent.Touched:Connect(ontouch)

I don’t think it has to do with the sit script at all anymore. It has do to with a script that has someone joining the game

Can you search in all of the scripts? By using the find in all scripts windows, if there’s anything like PlayerAdded?
Only script like that I think can affect only when a player joins

2 Likes

Press Ctrl + Shift + F, then search for LocalPlayer or PlayerAdded

2 Likes

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.