( I answered this myself fell free to check out what I did and use it in your game if you like ) Right now I'm trying to make a script that makes a starting screen appear for players in the lobby team it works but if the player resets or dies the GUI is not loaded in again if they are at the lobby team. Here is the script fell free to ask me any questions about it
01 | local Players = game:GetService( "Players" ) |
02 | local teams = game:GetService( "Teams" ) |
03 |
04 | local function onCharacterAdded(character) |
05 | print (character.Name .. " has spawned" ) |
06 | local respawning_player = game.Players:FindFirstChild(character.Name) |
07 | print ( "player has been found" ) |
08 | if respawning_player.Team = = teams.Lobby then |
09 | print (character.Name .. " is in the lobby" ) |
10 | local Starting_Screen = game.ServerStorage.UI.StartingScreen:Clone() |
11 | Starting_Screen.Parent = respawning_player.PlayerGui |
12 | print (character.Name .. " now can see the starting screen" ) |
13 | end |
14 | end |
15 |
After a couple hours of testing I finally fixed it, and here is the script. The main thing I did was add the wait(0.2) at line 8 this made it work not exactly sure why but it works now, so here you go ( if you know why this happened I would like it if you committed it thanks )
01 | local Players = game:GetService( "Players" ) |
02 | local teams = game:GetService( "Teams" ) |
03 |
04 | local function onCharacterAdded(character) |
05 | print (character.Name .. " has spawned" ) |
06 | local respawning_player = game.Players:FindFirstChild(character.Name) |
07 | if respawning_player.Team = = teams.Lobby then |
08 | wait( 0.2 ) |
09 | local Starting_Screen = game.ServerStorage.UI.StartingScreen:Clone() |
10 | Starting_Screen.Parent = respawning_player.PlayerGui |
11 | print (respawning_player.Name .. " now can see the starting screen" ) |
12 | end |
13 | end |
14 |
15 |
16 | local function onPlayerAdded(player) |
17 | player.CharacterAdded:Connect(onCharacterAdded) |
18 | end |
19 |
20 | Players.PlayerAdded:Connect(onPlayerAdded) |
( more notes how to use it ) -- Put this as a normal script in workspace -- In line 9 the .UI is a folder just remove this if you don't want it to be in a folder