Im trying to make an attack on titan game and i want to clone the characters player model and parent it to serverstorage (essentially acting as a backup) so once the titan body dies i can clone it, tp to my desired position and give the player control of their human body again.
When i join the game im met with an error saying that im trying to index nil with .Name
Ive tried doing some debugging with pcall and other stuff but still dont know why.
player.CharacterAdded:Connect(function(character)
-- Wait for character to load fully
local titanChoice = Instance.new("StringValue")
titanChoice.Name = "TitanChoice"
titanChoice.Value = "None" -- default or blank
titanChoice.Parent = player
character:WaitForChild("Humanoid")
character:WaitForChild("HumanoidRootPart")
print("Character before cloning:", character)
if not character then
warn("Character is nil! Cannot clone.")
return
end
-- Clone the character model and store it in ServerStorag
local storedModel = character:Clone()
storedModel.Name = player.Name .. "_HumanBackup"
storedModel.Parent = game:GetService("ServerStorage")
end)
end)