Best way to give a gui to players with CharacterAutoLoads set to false?

Basically struggling to have the gui stay there with it set to false

This is what i tried, and of course it didnt work

local MenuGui = game.StarterGui.Main

if game.StarterGui:FindFirstChild("Main") then
	MenuGui.Parent = game.ReplicatedStorage
end

----

function AddGui(Player)
	local gui = MenuGui:Clone()
	gui.Parent = Player.PlayerGui
end

function AddedPlayer(Player)
	AddGui(Player)
	
	Player.CharacterAdded:Connect(function(Character)
		AddedCharacter(Character, Player)
	end)
end

(Some code has been cut out, shouldn’t matter to much what it was)

Was there any errors in the output?

no, although after the player respawns they no longer have the gui

I’m not sure if you ever actually load the character or not but, this may be because the CharacterAdded event will only fire if CharacterAutoLoads is set to true. Try making your own bindable event for when you manually load the character, or call the AddedCharacter function everytime you manually load the character.

in another script i have it on a remote event to load the character, but when the character dies and respawns, it doesnt have the gui

Try putting a print statement in

	Player.CharacterAdded:Connect(function(Character)
                print("CharacterAdded event fired")
		AddedCharacter(Character, Player)
	end)

Does anything print in the output when you load the character?

yea, the character event is fine, ill just show the entire script

local Players = game.Players

Players.CharacterAutoLoads = false
local MenuGui = game.StarterGui.Main

if game.StarterGui:FindFirstChild("Main") then
	MenuGui.Parent = game.ReplicatedStorage
end


function OnSpawnIn(Gui, Player, Character)
	
end

function AddGui(Player)
	local gui = MenuGui:Clone()
	gui.Parent = Player.PlayerGui
end

function PlayerDied(Player)
	wait(2)
	Player.Character:Remove()
	Player.PlayerGui.Main.Menu.Visible = true
end

function AddedCharacter(Character, Player)
	OnSpawnIn(Player.PlayerGui.Main, Player, Character)
	Player.PlayerGui.Main.Menu.Visible = false
	print(Player.PlayerGui.Main.Menu)
	print(1)
	Character.Humanoid.Died:Connect(function()
		PlayerDied(Player)
	end)
end

function AddedPlayer(Player)
	AddGui(Player)
	
	Player.CharacterAdded:Connect(function(Character)
		AddedCharacter(Character, Player)
	end)
end

Players.PlayerAdded:Connect(AddedPlayer)

If you don’t need to reset the gui you can set the ResetOnSpawn property of the ScreenGui to false, and when the player dies the UI wont be removed from the players PlayerGui

1 Like

ohh, i thought it was automaticly set to off, no wonder i was so confused

1 Like