Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to prevent a character from auto-loading?

Hello!

Question: I want to prevent the character from being added to the game, until the press the "Play" button inside my ReplicatedFirst script. How do I make this work?

I know it has something to do with CharacterAdded, and maybe a RemoteEvent, but all my attempts thus far have failed. So in my scripts below, I've only included the parts that do work correctly.

This is my Local Script inside ReplicatedFirst that starts the moment the player beings:

local Players = game:GetService("Players")
local Player = game.Players.LocalPlayer

script.Parent:RemoveDefaultLoadingScreen()
local PlayerGui = game.Players.LocalPlayer:WaitForChild("PlayerGui")
PlayerGui:SetTopbarTransparency(0)
 
local screen = script:WaitForChild("LoadingScreen")
local bar = screen.Frame.LoadingBar.Bar
local text = screen.Frame.LoadingBar.LoadingText
local button = screen.Frame.PlayButton

button.Visible = false

screen.Parent = PlayerGui
 
local count = 0
while count <= 100 do
 text.Text = count .. "%"
 bar:TweenSize(UDim2.new(count / 100, 0, 1, 0), "Out", "Quad", .01)
 count = count + 1
 wait() 
end

button.Visible = true

button.MouseButton1Down:connect(function()
screen:Destroy()
local PlayerGui = game.Players.LocalPlayer:WaitForChild("PlayerGui")
PlayerGui:SetTopbarTransparency(1)
Player:LoadCharacter()

end)


I don't want to delay/prevent re-spawning, just prevent the auto-spawn the first time the player enters the game. Any advice would be much appreciated. :) Thanks!

2 comments

1

You could always just store their characters in a hidden box while they're in the loading screen.

0

Thanks for the suggestion! How would I go about this? I'd rather prevent them from loading period as my game does have an intermission/round system that would force the player to spawn onto the map, even if the Loading screen is still going on.

2 answers

✓ Accepted answer

Hope this helps! Straight from the good old wiki!

local respawnDelay = 5
 
game.Players.CharacterAutoLoads = false
 
game.Players.PlayerAdded:connect(function(player)
	player.CharacterAdded:connect(function(character)
		-- find the humanoid, and detect when it dies
		local humanoid = character:FindFirstChild("Humanoid")
		if humanoid then
			humanoid.Died:connect(function()
				wait(respawnDelay)
				player:LoadCharacter()
			end)
		end
	end)
	player:LoadCharacter() -- load the character for the first time
end)

Script found on link

7 comments

0

Thanks for the response! :) I'm not looking to delay the respawn each time, but just the first time.

1

Then make it work once? just remove the whole thing but keep the game.Players.CharacterAutoLoads = false and use player:LoadCharacter() to load it the first time!

1

And like after you did the load character once just set characterautoloads to true!

0

Ah! Thanks for the clarification! I tried that, but the characters are still spawning in the game. I edited my main post script to reflect the changes, do you see where I went wrong here?

0

I'm accepting this answer too, because it helped with the later problem of having the player respawn after death, after disabling the characterautoloads. :) Thank you!!

1

Glad to help. I'll try to fix your current script later on today too :)

0

No need good sir, I was able to sort it out with the use of a RemoteEvent! :) Your help on how to bring them back after death was invaluable!

There's a setting in Players called CharacterAutoLoads. Once set to false, you use

<Player>:LoadCharacter() -<Player> is reference to the Player you want to spawn.

4 comments

0

Thank you for the response! I disabled CharacterAutoLoads under Players, which did indeed disable the CharacterAutoLoads, but my script doesn't re-enable this. I edited my script in my initial post if you have an idea? :) Thank you again!

0

Update: You were correct, this was the easiest way to do it. :) Disabled CharacterAutoLoads, then the LoadCharacter() was by far the easiest way. Thank you!

0

Actually, I take that back. :D Error: LoadCharacter can only be called by the backend server.

0

And that was corrected by making it a RemoteEvent, except now when the player dies, they don't respawn. XD

This discussion is preserved as it was. New answers, comments, and votes are closed.