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

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

( 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

local Players = game:GetService("Players")
local teams = game:GetService("Teams")

local function onCharacterAdded(character)
	print(character.Name .. " has spawned")
	local respawning_player = game.Players:FindFirstChild(character.Name)
	print("player has been found")
	if respawning_player.Team == teams.Lobby then
		print(character.Name .. " is in the lobby")
		local Starting_Screen = game.ServerStorage.UI.StartingScreen:Clone()
		Starting_Screen.Parent = respawning_player.PlayerGui
		print(character.Name .. " now can see the starting screen")
	end
end
 
local function onCharacterRemoving(character)
	print(character.Name .. " is despawning")
end
 
local function onPlayerAdded(player)
	player.CharacterAdded:Connect(onCharacterAdded)
	player.CharacterRemoving:Connect(onCharacterRemoving)
end
 
Players.PlayerAdded:Connect(onPlayerAdded)

2 comments

0

Try setting the ResetOnSpawn property of your GUI to true.

0

Its already set to true

1 answer

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 )

local Players = game:GetService("Players")
local teams = game:GetService("Teams")

local function onCharacterAdded(character)
	print(character.Name .. " has spawned")
	local respawning_player = game.Players:FindFirstChild(character.Name)
	if respawning_player.Team == teams.Lobby then
		wait(0.2)
		local Starting_Screen = game.ServerStorage.UI.StartingScreen:Clone()
		Starting_Screen.Parent = respawning_player.PlayerGui
		print(respawning_player.Name .. " now can see the starting screen")
	end
end
 
 
local function onPlayerAdded(player)
	player.CharacterAdded:Connect(onCharacterAdded)
end
 
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

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