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

How do I clone() from replicated storage?

Asked by 5 years ago

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

Log in to vote
0
Answered by 5 years ago

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)
0
Thanks a lot and for the additional hit.Parent menofmen1234 20 — 5y
0
No problem :) ServerLover38 21 — 5y
Ad
Log in to vote
0
Answered by
c0nc3rt 61
5 years ago

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!

Answer this question