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.