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

Object only clones once, and then my script edits the only clone, any fixes?

The code is here:


local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded
local humanoidroopart = character:WaitForChild("HumanoidRootPart")
local clone = game.ReplicatedStorage.Wall:Clone()


script.Parent.MouseButton1Click:Connect(function()

	
	clone.CFrame = humanoidroopart.CFrame * CFrame.new(Vector3.new(0,-3,-2.5))
	clone.Orientation = humanoidroopart.Orientation
	clone.Anchored = true
	clone.Parent = game.Workspace


end)

I get no errors.

1 answer

✓ Accepted answer

That is happening because you are only cloning it once right when you start the code. In order to create a clone every time that button is clicked, you are going to have to clone the object every time the button is clicked.

The fix is actually really simple, you just cut the line where you define the variable "clone" and paste it under the MouseButton1Click function.

To avoid any confusion, I have done so below:

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded
local humanoidroopart = character:WaitForChild("HumanoidRootPart")

script.Parent.MouseButton1Click:Connect(function()
    local clone = game.ReplicatedStorage.Wall:Clone()
    clone.CFrame = humanoidroopart.CFrame * CFrame.new(Vector3.new(0,-3,-2.5))
    clone.Orientation = humanoidroopart.Orientation
    clone.Anchored = true
    clone.Parent = game.Workspace
end)

If you have any further questions please let me know! Hope this helped!

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