Character switching deletes all UI

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

I want to switch the player character


  1. What is the issue? Include screenshots / videos if possible!

all of the ui gets deleted including scripts once the character is switched >:(


  1. What solutions have you tried so far? Did you look for solutions on the Creator Hub?

changind a few things, looking in the dev hub, but nothing mentions this bug
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!


local char = game.Players.LocalPlayer.Character
local charClone = game.ReplicatedStorage.charFolder:FindFirstChild(selectedChar["charName"])
local oldChar = plr.Character
charClone.Parent = workspace
charClone.Name = plr.Name
plr.Character = charClone
char = charClone
workspace.CurrentCamera.CameraSubject = plr.Character:FindFirstChild("Humanoid")
oldChar:Destroy()

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

Shot into the ball park, did you turn off ResetOnSpawn?

You could just copy all the stuff from the other character and input it into the player’s current character

the character isnt set to the original character’s position, and everything inside playerGui is deleted exept for the freecam ui (default roblox cam ui) even thou i didnt delete anything related to UI during switch

Well you can keep that character model around and just move the character to that pos

because i have to completely switch the character model

i will code smth to help ya please hold should take like 10 minutes

update: managed to get the character to go to position using a simple :pivotTo() command, and the character moves and stuff, but the UI is still deleted and i dont get why

update2: once i switch the character variable in the player instance, the ui gets deleted

no i didnt and also:
managed to get the character to go to position using a simple :pivotTo() command, and the character moves and stuff, but the UI is still deleted and i dont get why
and i found out that:
once i switch the character variable in the player instance, the ui gets deleted

wait, couldn’t you just copy the gui and put it into player gui if its broken?

because the script i use to switch it is in the UI

--Player model
local player = game:GetService("Players") -- insert the specific player

--table
local stuff = {}

--Before changing
for _,v in pairs(player.PlayerGUI:GetChildren()) do
	local newGUI = v:Clone()
	table.insert(stuff,newGUI)
	v:Destroy()
end

--INSERT CHANGING CHARACTER CODE HERE

--when its done
for _,v in pairs(stuff) do
	local newGUI = v:Clone()
	table.insert(stuff,newGUI)
	v.Parent = player.PlayerGUI
end

What this does is basically store the gui in a table, then reinserting it into the player’s player gui

you could just move it out of the gui, and make the gui use physical variables instead of vars stored in the script

so it’s not dependent on the current state of the script

i found out by asking the roblox AI that when switching the player.character variable, it completely deletes all UI associated with that character for some reason

so just reinsert it, like what that script does

k it switches and all, but theres no gravity or jumping now?

wait i think i know lemme check

edit: and it only works once too :frowning:

edit 2: fixed it it now works yay :smiley: