How do we clone a character?🛠️

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")  -- اضافه کردن سرویس Players
local CharactersFolder = ReplicatedStorage:WaitForChild("Characters")

Players.PlayerAdded:Connect(function(player)
	-- دسترسی به leaderstats و level
	local leaderstats = player:FindFirstChild("leaderstats")
	local levelValue = leaderstats and leaderstats:FindFirstChild("level")
	
	-- بررسی سطح و تخصیص شخصیت
	if levelValue then
		local level = levelValue.Value
		if level >= 100 then
			player.Character = CharactersFolder:FindFirstChild("Character4")
		elseif level >= 50 then
			player.Character = CharactersFolder:FindFirstChild("Character3")
		elseif level >= 20 then
			player.Character = CharactersFolder:FindFirstChild("Character2")
		elseif level >= 10 then
			player.Character = CharactersFolder:FindFirstChild("Character1")
		else
			player.Character = CharactersFolder:FindFirstChild("Character0")
		end
	end
end)

I’m not a skilled scripter and I don’t really understand scripting much
I want the player to change their character when they reach a level, but the problem is that I got the item storage system in the “Free modle” and it really worked, but I heard that cloning a character will make the player get a character without items
The problem is that the server needs to check for level changes quickly and the player’s items need to be copied every second so that if the character changes, nothing happens and it is given to them
Please someone solve my problem

4 Likes

you aren’t using :clone(), but I’m not sure that would work here anyway; obviously thats one issue, but I don’t have much experience in character stuff so I dunno if thats how you change someone’s character.
oh also its connected to player added, so it only fires when someone joins, and not when their level actually changes.

3 Likes

issues:

  1. your event isnt being binded to a level change, so the player will have to rejoin to get their new character
  2. you would need to :Clone() the character to make this work
1 Like

The truth is, I don’t know anything about scripting, I know a little bit
Can you write it and give it to me?
And the problem is not only this, there is also the problem of checking the server and saving the items

1 Like

I think this should work, should be pretty easy to fix any random syntax errors I made though.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")  -- اضافه کردن سرویس Players
local CharactersFolder = ReplicatedStorage:WaitForChild("Characters")

Players.PlayerAdded:Connect(function(player)
	-- دسترسی به leaderstats و level
	local leaderstats = player:FindFirstChild("leaderstats")
	local levelValue = leaderstats and leaderstats:FindFirstChild("level")
	
	-- بررسی سطح و تخصیص شخصیت
	if not levelValue then return end
    levelValue:GetPropertyChangedSignal("Value"):Connect(function()
		local level = levelValue.Value
		if level >= 100 then
			player.Character = CharactersFolder:FindFirstChild("Character4"):Clone()
		elseif level >= 50 then
			player.Character = CharactersFolder:FindFirstChild("Character3"):Clone()
		elseif level >= 20 then
			player.Character = CharactersFolder:FindFirstChild("Character2"):Clone()
		elseif level >= 10 then
			player.Character = CharactersFolder:FindFirstChild("Character1"):Clone()
		else
			player.Character = CharactersFolder:FindFirstChild("Character0"):Clone()
		end
	end)
end)

this is also, not that efficient, since it fires every single time the property changes without checking if you currently already have the correct character, and also doesn’t fire when you first join, but its just a basis ig, you can fix it up.

2 Likes

Even though you couldn’t solve my problem, I appreciate you taking the time to really value me without getting anything in return.