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

Making a Clone?

I do know how to clone a part, but I am trying to clone it and put the clone to a certain position. But it doesn't go there and there is no clone where I wanted it to go.

test = script.Parent

game.Players.PlayerAdded:connect(function()
	wait(1)
	test:Clone()
	test2 = test:Clone()
	test2.Position = Vector3.new(-132.901, 0.5, -81.011)
end)

or I tried this:

knife = game.Lighting.Knife

game.Players.PlayerAdded:connect(function(plr)
	knife:Clone()
	knife2 = knife:Clone()
	knife2.Parent = plr.Backpack
end)

2 answers

✓ Accepted answer

Let's start with your first code. It looks relatively fine, with the exception on one thing. You forgot to parent the part (presumably to workspace)! Here's a quick fix:

local test = script.Parent

game.Players.PlayerAdded:connect(function()
    wait(1)
    local test2 = test:clone()
    test2.Position = Vector3.new(-132.901, 0.5, -81.011)
    test2.Parent = game.Workspace
end)

Your second code looks more to be a problem in terms of delay. From what I can tell, you aren't allowing the program to wait for the necessary pieces, causing it to simply not work. Here's (hopefully) a fix!

local knife = game:GetService("Lighting"):WaitForChild("Knife")

game.Players.PlayerAdded:connect(function(plr)
    local knife2 = knife:clone()
    knife2.Parent = plr.Backpack
end)

Hope this helped! If you have any questions about what I did to change it, feel free to reply to this answer! :)

Well sometimes when you do the PlayerAdded event it takes a while for the Backpack to load. So you might want to use the method called :WaitForChild(). This can wait for your Backpack to load so.. Something like this:

knife = game.Lighting.Knife
game.Players.PlayerAdded:connect(function(plr)
    knife:Clone()
    knife2 = knife:Clone()
    knife2.Parent = plr:WaitForChild("Backpack")
end)

So that's your problem with that and the first script your problem is probably I hope you're using Server Scripts. Also your problem with that might be if you didn't place the object test in Workspace you won't be able to see it. So that's all the issues I could find in your script.

I hope I helped and thank you for reading this answer!

~~ KingLoneCat

2 comments

0

This helped! I would accept the answer but Uglypoe gave me good answers to both. And I would upvote but I have no reputation.

0

It's ok thanks a lot for telling me as to why you accepted his answer over mine.

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