I am making a game that morphs players in and out of a morph as rounds go and end, and in order to do this so the player doesn’t automatically get switched back to their default character instead of the morph when I spawn them in with it I used a script to turn off CharacterAutoLoads when the player joins the game. But then once a round ends I use LoadCharacter on every player and everything breaks (the UI is still visible and all) as all scripts that update playerGui like the countdown break and say that what needs to be referenced is nil. I have tried spawning in all the Gui upon joining but maybe I need to do it once I use loadCharacter as it might already be spawned in?
When you loadCharacter, the old scripts will, along with the old characters, get killed. Considering that they’re still running, they may error as their references are now broken.
You should destroy the player’s character and the scripts inside them which is used to create the GUI, and then copy over a new set of them.
If the scripts which handles the GUI are not within the character, you have to make sure that they update to the new character when the character is re-loaded.
For more specific help, it would be nice if you provided the scripts that was breaking, their hierarchy in the explorer, and information such as wether or not the character is destroyed before it is loaded again.
Yep, that should be how it works. StarterGui loads things into the character, and if you call LoadCharacter again, the previous character is parented to nil, so Script.Parent would no longer be existant. (I assume)
function gameEndProcedure()
debounce = true
table.clear(_G.evilsTable)
table.clear(_G.survivorTable)
roundBool = false
_G.EnemySelectorActivated = false
for i, plr in pairs(players:GetChildren()) do
local character = plr.Character or plr.CharacterAdded:Wait()
table.insert(_G.survivorTable, plr.UserId)
character:Destroy()
plr:LoadCharacter()
for _, ui in pairs(game.StarterGui:GetChildren()) do
local u = ui:Clone()
u.Parent = plr.PlayerGui
end
end
end
WAIT NO
In your serverscript, don’t clone the ui to the PlayerGui unless you know they dont exist there. If there is already a set of ui there, don’t clone it again
Sorry went to sleep, but I’ll try this out. For whatever the reason when I tried out the previous solution of if blockVal ~= nil, it worked and the GUI still worked as it should for some reason? I couldn’t tell you