Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to prevent a character from auto-loading?

Asked by 6 years ago
Edited 6 years ago

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!

1
You could always just store their characters in a hidden box while they're in the loading screen. mattscy 3725 — 6y
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. Never2Humble 90 — 6y

2 answers

Log in to vote
1
Answered by 6 years ago

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

0
Thanks for the response! :) I'm not looking to delay the respawn each time, but just the first time. Never2Humble 90 — 6y
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! DanielDeJong3 158 — 6y
1
And like after you did the load character once just set characterautoloads to true! DanielDeJong3 158 — 6y
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? Never2Humble 90 — 6y
View all comments (3 more)
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!! Never2Humble 90 — 6y
1
Glad to help. I'll try to fix your current script later on today too :) DanielDeJong3 158 — 6y
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! Never2Humble 90 — 6y
Ad
Log in to vote
1
Answered by 6 years ago

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.
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! Never2Humble 90 — 6y
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! Never2Humble 90 — 6y
0
Actually, I take that back. :D Error: LoadCharacter can only be called by the backend server. Never2Humble 90 — 6y
0
And that was corrected by making it a RemoteEvent, except now when the player dies, they don't respawn. XD Never2Humble 90 — 6y

Answer this question