Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Trying to clone myself but it just prints but does not clone?

My Problem

I am trying to put a code that clones the character, but when I press it. It says my name and I put the code .Parent = game.Workspace it does not show it on Workspace, any help?

Code

local player = game.Players.LocalPlayer

local character = player.CharacterAdded:Wait() or player.Character

wait()

script.Parent.MouseButton1Click:Connect(function()

local ds = game.Workspace:FindFirstChild(player.Name)

print(ds)

if ds.Parent.Name == player.Name then

local clone = ds:Clone()

clone.Parent = game.Workspace

clone:SetPrimaryPartCFrame(character.HumanoidRootPart.CFrame * CFrame.new(0,0,0))

end

end)

1 comment

0

You should actually do character:Clone() instead of ds:Clone(). "ds" and "character" are actually the same exact thing.

1 answer

✓ Accepted answer

Archivable property

All instances have an Archivable property. This determines if an object can be cloned, or saved

By default roblox characters have this set to false and when you try cloning without setting it to true, instance.Clone will return nil.

Also your script has lots of "fluff", lots of what you are doing is redundant.

ds is a misleading variable name, it does not clearly show its purpose in the code. character was one of your variables but you never used it.

What you can do is something like this:

local button = script.Parent;
local client = game:GetService("Players").LocalPlayer; --// Get services using :GetService(serviceName)
local character = client.Character or client.CharacterAdded:Wait(); --// You have the order wrong.
character.Archivable = true;
 
--[[ 
	/*
	Check for character first. 
	If it exists, assign the character variable to the character model. 
	If not, wait for the character. Yours is waiting first when it is possible they loaded in already.
	*/
--]]

button.Activated:Connect(function() --// Activated works for other devices too
	local clone = character:Clone();
	clone:SetPrimaryPartCFrame(character.HumanoidRootPart.CFrame));
end);

There is no point in multiplying it by CFrame.new(0, 0, 0). It won't do anything.


Finally, please, please, please indent. Separating each statement with a line of whitespace is not a substitute for indenting properly and doesn't make the code any more readable.

If indenting is truly hard for you, I have made a tutorial which covers when and when not to indent. You can find it here.


I hope I helped you, and if I did, then don't forget to hit that "Accept Answer" button. It helps the both of us out.

2 comments

0

Thanks for the answer, but still not working

0

I also noticed you didn't make add parents, thank you for the answer!

This discussion is preserved as it was. New answers, comments, and votes are closed.