Weird Bug in my script

When the Player spawns trough player:loadcharacter() the guis will randomly disappear for no reason, I don’t got a single line that tell the game to delete all guis.

The main menu script: (only the end is important)

LobbyMusic.Volume = 0
TeamChangeButton.Text = "Your Team:\n"..playerteam.."\nClick to Change Team"

player:GetPropertyChangedSignal("TeamColor"):Connect(function()
	playerteam		=player.Team.Name
end)

local LMT = TweenService:create(LobbyMusic, TweenInfo.new(100), {Volume = 10})
local function MenuON()
	MainMenu.Enabled = true
	LMT:Play()
	LobbyMusic:Play()
	LMT.Completed:Wait()
end
player.CharacterAdded:Connect(MenuON)
--task.spawn(MenuON)

local function Play()
	if playerteam == Spectators then
		PlayButton.Text		="Please Change Your Team"
		ErrorSound:Play()
		wait(3)
		PlayButton.Text		="Play"
	else
		local LoadCharacter = ReplicatedStorage.LoadCharacter
		LoadCharacter:FireServer(player)
		SpawnWeaponRE:FireServer(player)
		MainMenu:Destroy()
		LobbyMusic.Volume = 0
		ClickSound:Play()
	end
end

PlayButton.MouseButton1Down:Connect(function()
	Play()
end)

Basically when pressing the play button the player gets loaded and the main menu destroyed, but it is also destroying all the other GUIs.
Even more weird: The StarterGUIs aren’t cloning into the playergui after respawning

1 Like

Did you try setting the ScreenGui’s ResetOnDeath property to false?

1 Like

All my ScreenGuis have ResetOnSpawn on false

1 Like

Update: Guis are now cloning to PlayerGui
Except: the MainGui which was destroyed, but there is still an MainMenu in starterGui which isn’t getting cloned

1 Like

“The LoadCharacter Player function creates a new character for the player, removing the old one. It also clears the player’s Backpack and PlayerGui.”

Maybe it has to do with this

1 Like

But the player is only loaded when he presses the play button?

1 Like

Well you said that the UI only disappears when the function LoadCharacter is firing right? Could you also provide the ServerScript? Because I think the issue may lays there

1 Like

There isn’t really much in the ServerScript

local wfc				=game.WaitForChild
local ReplicatedStorage		=game:GetService("ReplicatedStorage")
local LoadCharacter			=wfc(ReplicatedStorage,"LoadCharacter")

LoadCharacter.OnServerEvent:Connect(function(player)
	player:LoadCharacter()
end)
1 Like

Heres another part of the LocalScript

local PlayerGui	=wfc(player,"PlayerGui")
repeat wait() until ffc(PlayerGui,"MainMenu")

Basically after the loading finishes, the Loading Script will clone all gui elements to the PlayerGUI AND the StarterGui and destroys itself after.

It’s supposed that the StarterGui clones the MenuGui tothe playerGui each time the player dies
but the mainmenu isn’t either getting detected or my script is just broken

1 Like

Maybe you’re deleting the ScreenGui where the whole UI is in?

Well I had different ScreenGui, but I kinda fixed the Error, I enabled ResetonSpawn, and also added the LoadCharacter at the teamchange button
Also changed it a bit tho, now im struggeling with something other

function MenuON()
	local LMT = TweenService:create(LobbyMusic, TweenInfo.new(100), {Volume = 10})
	--if not ffc(PlayerGui,"MainMenu") then
	print("TTTTT")
	MainMenu:Clone().Parent = PlayerGui
	LMT:Play()
	LobbyMusic:Play()
	--LMT.Completed:Wait()
	--end
end
player.Humanoid.Died:Connect(MenuON)

--task.spawn(MenuON)
function Play()
	local LMT = TweenService:create(LobbyMusic, TweenInfo.new(100), {Volume = 10})
	if playerteam == Spectators then
		PlayButton.Text		="Please Change Your Team"
		ErrorSound:Play()
		wait(3)
		PlayButton.Text		="Play"
	else
		SpawnWeaponRE:FireServer()
		MainMenu:Destroy()
		LMT:Play()
		LMT:Cancel()
		LobbyMusic.Volume = 0
		LobbyMusic:Stop()
		ClickSound:Play()
	end
end

basically, the tween is only stopping in the Play() function when it is played again
when the player spawns then the MenuON() function isn’t player for some reason