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

How do I clone() from replicated storage?

Okay so this is my code so far....

game.Workspace.Baseplate.Touched:Connect(function(hit)
	print("He touched the baseplate"..hit.Name)
	game.ReplicatedStorage.Part2:Clone()
	
	
end)

Can someone explain to me how to fix it?

and there is already a part in replicatedstorage called "Part2"

so does this only work with serverstorage or can I do it wtih replicated?

2 answers

✓ Accepted answer

After you clone an object, you have to set its parent and its position (otherwise your clone isn't going to appear anywhere), so assuming you want to place your object in the workspace, you'll need to modify your code to this:

game.Workspace.Baseplate.Touched:Connect(function(hit)

    -- Off-topic, but it should be hit.Parent.Name because the hit.Name will usually give the name of the body part of the player that touched it, and because the player is the parent of the part, it should be hit.Parent.Name

    print("He touched the baseplate"..hit.Parent.Name)

    -- Assign a reference variable for your part

    local part2 = game.ReplicatedStorage.Part2:Clone()

    -- Assign a parent to your clone (in this case, the workspace, but you can assign any parent according to your needs)

    part2.Parent = workspace

    -- Assign your clone a position (replace x, y and z with the coordinates of the position you want to place your clone)

    part2.CFrame = CFrame.new(Vector3.new(x,y,z))

end)

2 comments

0

Thanks a lot and for the additional hit.Parent

0

No problem :)

I'm late but this is my code so far

I recomended you should code the connect function like this

local part2 = game.ReplicatedStorage.Part2 --just shortened the part name using local

function hit
    print("He touched the baseplate"..hit.Parent.Name) --You can't get char name by hit.Name
    part2:Clone().Parent = workspace --clone the part and set the parent of the part is the workspace.

end

game.Workspace.Baseplate.Touched:Connect(function(hit)) --look better?

Hope i helped you!

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