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

GUI is only being given to each player when they join but not re spawn? [ answered ]

Asked by 4 years ago
Edited 4 years ago

( 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

01local Players = game:GetService("Players")
02local teams = game:GetService("Teams")
03 
04local 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
14end
15 
View all 25 lines...
0
Try setting the ResetOnSpawn property of your GUI to true. AntiWorldliness 868 — 4y
0
Its already set to true robloxian_colby 22 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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 )

01local Players = game:GetService("Players")
02local teams = game:GetService("Teams")
03 
04local 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
13end
14 
15 
16local function onPlayerAdded(player)
17    player.CharacterAdded:Connect(onCharacterAdded)
18end
19 
20Players.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

Ad

Answer this question