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

Clone scipt not working?

So, What's supposed to happen is, it clones the tower than puts the clone in Workspace. What's happening is, it brings the tower into Workspace just fine. But it doesn't clone it. And I don't want to copy and paste a bunch of towers in Lighting, (where I keep the tower) cause it makes my game lag. Help...?

****Here's the script:

function Clicked()
	game.Lighting.ObservationTower:Clone()
	game.Lighting.ObservationTower.Parent = game.Workspace
	
end

script.Parent.MouseButton1Click:connect(Clicked)

FYI, the thing you are clicking is not a part. It is a GUI.

2 answers

✓ Accepted answer

game.Lighting.ObservationTower:Clone().Parent = game.Workspace

Explanation: You are cloning it, but because the Clone method doesn't automatically parent the clone, you have to do it yourself. Clones also aren't re-accessible unless you have the direct path (i.e., game.Lighting.ObservationTower) or you assign it to a variable.

Lighting for use of storage has been deprecated/replaced with ReplicatedStorage. I'd recommend using that instead.

Your problem is that you're not moving the clone into the workspace, you're simply moving the tower itself. To fix this, you simply need to assign the clone to a variable. We can call it anything, but for simplicity's sake, let's just call it "clone".


So, to add this into your code, it would look like this:

function Clicked()
	local Clone = game.Lighting.ObservationTower:Clone()
	Clone.Parent = game.Workspace
end

script.Parent.MouseButton1Click:connect(Clicked)

So now it should work correctly!

Also, as a side note, like DeadToMe stated, Lighting has been deprecated for storage. It won't really make a difference, but you should consider switching from Lighting to ServerStorage or ReplicatedStorage.


Anyways, if you have any further problems/questions, please leave a comment below, and I'll see what I can do.

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