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

Why won't this clone?

I have the following code in a LocalScript, which is in a ImageButton. But it won't clone. Why?

script.Parent.MouseButton1Click:connect(function()
	a = game.Lighting:FindFirstChild("First") --The name of the thing is called First.
	a:Clone(game.Workspace)
	a.VehicleSeat.Vars.Owner.Value = game.Players.LocalPlayer.Name
end)

There is no Output...

3 answers

✓ Accepted answer

I've never seen :clone() used that way, with the parent as a parameter, and I can't find any documentation on the wiki that says it can work with that. But if that has worked for you before, sure.

Assuming that clone can work that way, I think I might see your problem. In line 2, you're setting a to a thing called "First" in Lighting. Great. Then, line 3, you clone it and put the copy into Workspace. Then you set the owner value in a. The issue that a is a thing in Lighting, and that never changed. You changed the owner variable of the backup model in lighting, not the new one that you copied into workspace. You actually just copied it into workspace and forgot about it. You probably instead want a to be a reference to your new thing, rather than the original backup model in Lighting. I would suggest:

script.Parent.MouseButton1Click:connect(function()
	a = game.Lighting:FindFirstChild("First"):clone()
	a.Parent = game.Workspace
   	a.VehicleSeat.Vars.Owner.Value = game.Players.LocalPlayer.Name
end)

2 comments

0

Grenaderade's proposed solution also has the issue of changing the variable in the model in Lighting, rather than the newly made model in Workspace.

0

Thanks a lot!! Want some credit in my game?

Clone(game.Workspace) wouldn't be possible.

script.Parent.MouseButton1Click:connect(function()
    a = game.Lighting:FindFirstChild("First") --The name of the thing is called First.
    a:Clone().Parent = Workspace
    a.VehicleSeat.Vars.Owner.Value = game.Players.LocalPlayer.Name
end)

Strange, I'm having the same problem too with my own script, I think Roblox broke this coding for GUIs aswell. :/ Silly isn't it?

Edited;

Instead of doing a:Clone() and a.Parent seperate, try it like this;

local a = game.Lighting:FindFirstChild("First",true):Clone() --The name of the thing is called First.
script.Parent.MouseButton1Click:connect(function()
local b=a:Clone()
b.VehicleSeat.Vars.Owner.Value = game.Players.LocalPlayer.Name
end)

Hope this helped!

1 comment

0

I fixed it. But I have a follow up problem. when it clones, the model is taken away from Lighting, so you can only clone it once...

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