Hi, recently I coded a character selector for a game I’m working on, each character is kept in replicated storage and when you press a gui button the custom character replaces the player’s character ,but when pressing a different gui button for a different character after switching the original player character for another custom character it doesn’t change. It sticks with the first character I switched to. So I was wondering if I had to redefine how I grab the character and I tried doing that but I got no results so here’s my code for changing the character and if anyone could help I’d really appreciate it.
local Jason1 = game.ReplicatedStorage.Jason
local Player = game.Players.LocalPlayer
local button = script.Parent
local StarterCharacterScripts = game.StarterPlayer.StarterCharacterScripts:GetChildren()
local CharacterSelector = game.StarterGui["Old Character Slector"].Enabled
local LocalScripts = {}
local humanoid = Player.Character:WaitForChild("Humanoid")
local walkspeed = humanoid.WalkSpeed
walkspeed = 0
local rs = game:GetService("ReplicatedStorage")
local CanContinue = rs:WaitForChild("CanContinueRe")
local GUI = game.StarterGui["Old Character Slector"]
local function onButtonActivated() -- Checking if the player clicked on the block
local ChosenCharacter = Jason1:Clone()
local CurrentCharacter = Player.Character or Player.CharacterAdded:Wait()
local LocalScripts = {}
CharacterSelector = false
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
ChosenCharacter.Name = Player.Name
Player.Character = ChosenCharacter
ChosenCharacter.PrimaryPart.CFrame = CurrentCharacter.PrimaryPart.CFrame
GUI.Parent = game.Players.LocalPlayer.PlayerGui
CurrentCharacter:Destroy()
--script.Parent:GetChildren():Isa("Frame").Visible = false
for index2,item2 in pairs(LocalScripts) do
item2.Parent = ChosenCharacter
end
end
button.Activated:Connect(onButtonActivated)