Attempt to index nil with "Parent"

Hi!

I have trying to clone character before it got deleted.
but when i try to clone character and change parent there are error like my clone is nil

This is script i used on server side

plr.CharacterRemoving:Connect(function(me)
		local clonechar = me:Clone()
		
		if game.ServerStorage.Backup:FindFirstChild(plr.Name) then
			game.ServerStorage.Backup:FindFirstChild(plr.Name):Destroy()
		end
		clonechar.Parent = game.ServerStorage.Backup
 	end)

this is error i got

07:27:39.910 - ServerScriptService.Script:60: attempt to index nil with ‘Parent’

Thanks and sorry for bad english

Which place is the error in???

It error on line

Oh yea I had this error before you destroyed the backpack so cloning it or anything else wouldn’t be a option ! instead of :Destroy() :ClearAllChildren()

but when i trying to use me.Name it still print character name.

if it actually got clone but when i try to use clonechar.Name it print error?

You printed the name and then destroyed so it’ll print! Code is from start to end u can’t get order wrong!

Sorry for bad grammar I’m not fluent English

did you mean :Clone() is working too slow?

So there are no time enough to clone?

Nope! So look when I was making if you had a gun and chose a new the gun would be destroyed! Meaning it’s impossible to clone because it’s gone! So instead of :Destroy do :ClearAllChildren not hard

Characters, by default, don’t have Archiveable=true. IIRC, Clone doesn’t work with things that aren’t set to Archiveable.
me.Archiveable = true
local clonechar = me:Clone()

2 Likes

Then how do i do to clone character before it got actually remove, i need it to do this from this topic

Give the parent before u destroy the tool!

Why character Archiveable value didn’t true ?

plr.CharacterRemoving:Connect(function(me)
local clonechar = me:Clone()
clonechar.Parent = game.ServerStorage.Backup
if game.ServerStorage.Backup:FindFirstChild(plr.Name) then
game.ServerStorage.Backup:FindFirstChild(plr.Name):ClearAllChildren()
end

end)

I think it is archaic. People used to edit their games as a character rather than in Studio, and if you saved your game wile Archiveable is true, your character would be saved, and that’s bad. So characters default to non-archiveable so characters don’t accidentally get saved.

So is it ok to change it to true before it got deleted?

Try it like this:

game.Players.PlayerAdding:Connect(function(plr)
        plr.CharacterRemoving:Connect(function(me)
		local clonechar = me:Clone()
		
		if game.ServerStorage.Backup:FindFirstChild(plr.Name) then
			game.ServerStorage.Backup:FindFirstChild(plr.Name):Destroy()
		end
		clonechar.Parent = game.ServerStorage.Backup
 	end)

I already try it it print error like nothing is cloned and it nil

game.Players.PlayerAdding:Connect(function(plr)
        plr.CharacterRemoving:Connect(function(me)
		local clonechar = me:Clone()
		clonechar.Parent = game.ServerStorage.Backup
		if game.ServerStorage.Backup:FindFirstChild(plr.Name) then
			game.ServerStorage.Backup:FindFirstChild(plr.Name):Destroy()
		end
		
 	end)

Worked for me

Your issue is your using serverstorage. I’d recommend using replicatedstorage.

ServerStorage is better even Roblox says it in wiki!