How would I go about making the character selected from my gui stay after you die or respawn? I tried to make it so that the character clones when you respawn but I don't think I did it right.
My code - >
local Player = script.Parent.Parent.Parent
local Content = script.Parent.MainFrame.ScrollingFrame.Content
local Characters = game.ReplicatedStorage.Characters
local SetSubject = Characters.Parent.SetSubject
local BBW = script.Parent.MainFrame.ScrollingFrame.Content.BlackHairBW.BlackBlackFemale
local BWW = script.Parent.MainFrame.ScrollingFrame.Content.BlackHairWW.WhiteBlackFemale
for index,item in pairs(Characters:GetChildren()) do
item:FindFirstChild("Humanoid")
local Button1 = script.Parent.MainFrame.ScrollingFrame.Content.BlackHairBW.TextButton
local Button2 = script.Parent.MainFrame.ScrollingFrame.Content.BlackHairWW.TextButton
Button1.MouseButton1Down:Connect(function()
script.Parent.Enabled = false
local ChosenCharacter = BBW:Clone()
local CurrentCharacter = Player.Character
local LocalScripts = {}
for index2,item2 in pairs(game.StarterPlayer.StarterCharacterScripts:GetChildren()) do
if item2:IsA('LocalScript') then
table.insert(LocalScripts,item2:Clone())
else
item2:Clone().Parent = ChosenCharacter
end
end
CurrentCharacter.Health:Clone().Parent = ChosenCharacter
table.insert(LocalScripts,CurrentCharacter.Animate:Clone())
ChosenCharacter.Parent = workspace
Player.Character = ChosenCharacter
for index2,item2 in pairs(LocalScripts) do
item2.Parent = ChosenCharacter
end
SetSubject:FireClient(Player,ChosenCharacter.Humanoid)
local Connection
local function onDied()
wait(game.Players.RespawnTime)
Player:LoadCharacter()
script.Parent.Enabled = false
if Connection then
Connection:Disconnect()
end
end
Connection = ChosenCharacter.Humanoid.Died:Connect(onDied)
end)
