Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why won't this clone?

Asked by 10 years ago

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

Log in to vote
0
Answered by
Defaultio 160
10 years ago

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)
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. Defaultio 160 — 10y
0
Thanks a lot!! Want some credit in my game? fahmisack123 385 — 10y
Ad
Log in to vote
1
Answered by 10 years ago

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)

Log in to vote
0
Answered by 10 years ago

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!

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... fahmisack123 385 — 10y

Answer this question