The player is created before scripts run

It’s very inconvenient to have to re-write every PlayerAdded and CharacterAdded event connection to be compatible with the special needs of roblox studio because it creates the player (and maybe even the character) before running any of the scripts in the game.

What would be this

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		spawn(function()
			character.HumanoidRootPart.CFrame = CFrame.new(256, 10, 256)
		end)
	end)
end)

instead has to be disfigured into this

local function AddPlayer(player)
	local function AddCharacter(character)
		spawn(function() -- another unnecessary hack; see devforum.roblox.com/t//48808
			character.HumanoidRootPart.CFrame = CFrame.new(256, 10, 256)
		end)
	end
	player.CharacterAdded:Connect(AddCharacter)
	if player.Character then
		AddCharacter(player.Character)
	end
end
game.Players.PlayerAdded:Connect(AddPlayer)
for _, player in pairs(game.Players:GetPlayers()) do
	AddPlayer(player)
end)
8 Likes

Agreed. It’s pretty annoying having to write all that extra code just to properly test within Studio.

Assuming this is basically a race-condition issue, I guess the only fix I can think of is to make sure scripts run a single tick before adding any player object.

5 Likes

Unrelated question but is this game Filtering Enabled?

It’s studio, there is no filtering.

We’ll look into this, but can you just write a function to do this for you (ie: RunFunctionOnPlayerAdded(func))?

1 Like

That’s what he’s doing in the second code block in the OP I think. The issue is that it’s really ugly/cluttering to do that.

2 Likes

That’s currently what he is doing

However, it’d be nice if server scripts loaded before the player, and local scripts after the character :slight_smile:

4 Likes

This has always annoyed me, would love if it were fixed

Just to confirm, by “in studio”, you mean Play Solo, right? Testing via Test->Local Server, 1 Player should work the same as a deployed place, complete with support for FE. Play Solo is a special case, and kind of a compromise for fast iteration at the expense of not behaving identically to a separate server and client. Right now, getting all your startup code that works live to also work in Play Solo does usually require some extra boilerplate stuff to tolerate things being already loaded, near-zero latency, and transfer of the studio build camera over to being the in-game camera.

Yes, the problems are in Play Solo. Local servers seem to have no problem reproducing online behavior.