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

How Do I Clone My Model From ServerStorage and From Touching A Part?

Asked by
TtuNkK 37
5 years ago

Hi, I just started learning so please bear with me. I'm trying to clone a model called Test562 from the ServerStorage and from touching a part.

part = script.Parent

part.Touched:Connect(function()
local test2 = game.ServerStorage.Test562
test2.Parent = game.Workspace 
end)``

And if you guys can tell me how I can place the model to a specific position, that would be amazing.``

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

To make a copy of any instance with Archivable set to true, use Clone().

If you also want to position the model, use SetPrimaryPartCFrame(). (You have to set the PrimaryPart first because the PrimaryPart is nil by default.) Example:

local part = script.Parent -- Please use local variables
local debounce = true
part.Touched:Connect(function()
    if debounce == false then return end
    debounce = false
    if game:GetService("ServerStorage"):FindFirstChild("Test562") then
        local test = game:GetService("ServerStorage").Test562:Clone()
        test.Parent = workspace
        if test.PrimaryPart == nil then
            test.PrimaryPart = test.Core -- Assign the primary part first. Core is just an example of a child.
        end
        test:SetPrimaryPartCFrame(CFrame.new(Vector3.new(1,1,1)))
    end
    wait(3)
    debounce = true
end)
0
Thank you so much TtuNkK 37 — 5y
Ad

Answer this question