Is there a way to reload Player.PlayerScripts?

Pretty simple question and a weird one but basically heres how it works. I’m making a game thats suppose to have multiple places and before the game fully loads in it loads a model in that has all/most of the assets for the game including majority of the server scripts. The problem is though that I can’t really use the StarterPlayerScripts or StarterCharacyerScripts folders in game.StarterPlayer. This wouldn’t be an issue however since theres no telling when the first player loads in and the model loads in. It could become a bit buggy if the player ends up loading in before the model does.

One solution I thought of was to simply have the starterscripts in a seperate folder and clone them to the player on a PlayerAdded event. However for some stupid reason localscripts don’t work unless they are specifially in the PlayerScripts of PlayerGui folder. PlayerGui would work fine except that it reloads everytime the player dies which can be extremely annoying sometimes

It only works on the client because the server doesn’t have access to player scripts:

local function findScripts(p: Instance): {LocalScript | Script}
	local scripts = {}
	for _, v: Instance in pairs(p:GetDescendants()) do
		if v:IsA("LocalScript") or v:IsA("Script") then
			table.insert(scripts, v)
		end
	end
	return scripts 
end

local function reloadPlayerScripts()
	local player = game.Players.LocalPlayer
	local PlayerScripts = player:FindFirstChildWhichIsA("PlayerScripts")
	if not PlayerScripts then return end
	local scripts = findScripts(PlayerScripts)
	for _, v in pairs(scripts) do v.Enabled = false end
	for _, v in pairs(scripts) do v.Enabled = true end
end
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.