Roblox Studio Script Timeout With :LoadCharacter()

So, I’m working on a game, right? I figured it’d eventually probably be a multi-place game, so I set up a system where I can upload all the scripts in each service as separate models and then have one script in every place that automatically loads all of the scripts in. I got this idea from another topic I read, but that’s besides the point.

I noticed that my character would load in before all the scripts would and that would cause issues with scripts that looked for my character. I didn’t want to have to manually go into everything and put a :WaitForChild() everywhere that normally wouldn’t need it, so I decided to disable game.Players.CharacterAutoLoads, re-enable it after the scripts loaded in, and then manually load any players that came before it was re-enabled.

Initially, this worked just fine, and I was just working on all of my scripts from a separate testing place and the scripts would all upload to the main place just fine and I’d load in. Suddenly though, when I was testing just now, I got a script timeout error.

I had just finished making another script, so I wondered if it was that, but it linked me to the LoadScripts script and took me to the line that loaded the player’s character manually with :LoadCharacter()

Here’s the script:

-- Stopping Character Loading
game.Players.CharacterAutoLoads = false

-- Services
local is = game:GetService("InsertService")
local sp = game:GetService("StarterPlayer")
local debris = game:GetService("Debris")

-- Loading Models
local models = {
	ReplicatedStorage = is:LoadAsset(--[[insert id]]);
	ServerScriptService = is:LoadAsset(--[[insert id]]);
	ServerStorage = is:LoadAsset(--[[insert id]]);
	StarterGui = is:LoadAsset(--[[insert id]]);
	StarterPlayer = is:LoadAsset(--[[insert id]]);
	--StarterCharacterScripts = is:LoadAsset();
	StarterPlayerScripts = is:LoadAsset(--[[insert id]]);
}

-- Inserting Actual Models
local disabledList = {}

for name,model in pairs(models) do
	
	-- Inserting Everything
	for i,v in pairs(model:GetChildren()) do
		
		-- Disabling if Script
		for i,s in pairs(v:GetDescendants()) do
			if (s.ClassName == "Script" or s.ClassName == "LocalScript") and not s.Disabled then
				table.insert(disabledList,s)
				s.Disabled = true
			end
		end
		
		-- Parenting
		if name == "StarterCharacterScripts" then
			v.Parent = sp.StarterCharacterScripts
		elseif name == "StarterPlayerScripts" then
			v.Parent = sp.StarterPlayerScripts
		else
			v.Parent = game:GetService(name)
		end
		
	end
	
	-- Deleting Model
	debris:AddItem(model,0)
	
end

-- Re-enabling Scripts
for i,v in pairs(disabledList) do
	v.Disabled = false
end

-- Character Loading
game.Players.CharacterAutoLoads = true

for i,v in pairs(game.Players:GetChildren()) do
	v:LoadCharacter() -- Script timeout occurs on this line.
end

-- Deleting Script
debris:AddItem(script,0)

I tried adding a wait in the for loop, but it didn’t do anything. I commented out the whole manual character loading section:

for i,v in pairs(game.Players:GetChildren()) do
	v:LoadCharacter() -- Script timeout occurs on this line.
end

and my character didn’t load but it also didn’t give a script timeout error. I’ve come to the conclusion that it has to be the :LoadCharacter() function.

This all also started after a recent Roblox Studio update, so that could’ve been where it changed.

May I know what the exact error said?

Also, I’m a little confused with how your scripts are looking for your character. Why don’t you just access Player.Character only when you need it?

1 Like

image
^ That’s the error. Line 61 is the exact line that does :LoadCharacter()

Also, to answer your other question, I am referring to other scripts that are loaded in. I usually have a local char variable when I need it so I don’t have to always do player.Character 50 times.

What I was trying to do with this script was to pause automatic character loading, load in all of the scripts and assets, and then resume character loading. However, when I resume character loading afterwards, it doesn’t load in players that joined while automatic character loading was turned off, so I decided to just do that manually.

The reason I need to temporarily pause character loading in the first place is so that scripts from game.StarterPlayer.StarterCharacterScripts could properly load in.

Also, this used to work just fine before. I didn’t change anything in the script, and the only thing I could’ve changed was maybe the assets being loaded in, but that’s not what’s giving the error and crashing the test.

I have a feeling you’ll be getting yourself into a greater hassle by doing this than to change your scripts using Player.Character, after all that’s why it exists.

Regarding,

You could use the CharacterAdded event to run your scripts after the player’s character is added.

The issue isn’t that. The issue is that the scripts in game.StarterPlayer.StarterCharacterScripts won’t go into my character if my character loads in before the scripts do. That’s why I pause character loading while I load the scripts. However, it seems to be working now anyway, so I might just mark this as solved. Not sure why it stopped working in the first place.

1 Like