You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? i was trying change, a MainCharacter to Another Character, but when i change the character, about 4 second my character change to normal character.
-
What is the issue? When i change the main character to another character, about 4 second,my character change to normal character.
local Characters = game.ReplicatedStorage.Characters
local SetSubject = Characters.Parent.SetSubject
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(Player,data,oldcf)
print(data)
print(Player)
for index,item in pairs(Characters:GetChildren()) do
print(item.Name, data)
if item:FindFirstChild("Humanoid") and item.Name == data then
local ChosenCharacter = item:Clone()
local CurrentCharacter = Player.Character
local LocalScripts = {}
for index2,item2 in pairs(game.StarterPlayer.StarterCharacterScripts:GetChildren()) do
print(item2)
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
Player.Character.HumanoidRootPart.CFrame = oldcf
for index2,item2 in pairs(LocalScripts) do
item2.Parent = ChosenCharacter
end
SetSubject:FireClient(Player,ChosenCharacter.Humanoid)
local Connection
local function onDied()
print("adaadasd")
wait(game.Players.RespawnTime)
Player:LoadCharacter()
--script.Parent.Enabled = true
if Connection then
Connection:Disconnect()
end
end
local function asu()
print("asdsdasd2323")
end
asu()
onDied()
Connection = ChosenCharacter.Humanoid.Died:Connect(asu)
end
end
end)