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

Draggable Clone for Models?

Asked by 8 years ago
Edited 8 years ago

I'm trying to get one of my models to be cloned, turn a little transparent and then move with the mouse when I click on a button. I've made it so it is cloned and moves with the mouse but It breaks apart and they all try to put themselves where the mouse.target is. I want them to retain their model form and also I when I click I want the model to appear and the transparent clone is destroyed or even placed then the transparency is changed.

local player = game.Players.LocalPlayer

local mouse = player:GetMouse()

function Click ()

    local B = game.ReplicatedStorage.Headquarters

    local clone = B:Clone()

    clone:Clone().Parent = game.workspace.Buildings

    print "Cloned"

local part = workspace.Buildings.Headquarters

for i,child in pairs (part:GetChildren())do

mouse.Move:connect(function()
    if mouse.target then
        if mouse.target~=part then
            child.Position = Vector3.new(mouse.hit.p.X,mouse.hit.p.Y,mouse.hit.p.Z)

        child.Transparency = .5

        mouse.Button1Up:connect(function()
            child.Position = (mouse.UnitRay)
        end)

        end
    end
end)

end
end

workspace.Outline.ClickDetector.MouseClick:connect (Click)

Any Help will be Appreciated! Thank you.

1 answer

Log in to vote
0
Answered by
Klink45 20
8 years ago

You're overcomplicating it. To move a whole model, use the MoveTo() function.

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local b = game.ReplicatedStorage:WaitForChild("Headquarters")
local clickdetector = game.Workspace:WaitForChild("Outline"):WaitForChild("ClickDetector")

clickdetector.MouseClick:connect(function()
local newb = b:Clone()
newb.Parent = game.Workspace.Buildings
--You do not need to create a new variable for newb!
for i,v in pairs(newb:GetChildren()) do
if v:IsA("BasePart") then
v.Transparency = 0.5
end
end
v:MoveTo(mouse.Hit.p)--This will move a whole model!
mouse.Move:connect(function()
v:MoveTo(mouse.Hit.p)
end)
end)

To read more about the MoveTo() function: http://wiki.roblox.com/index.php?title=API:Class/Model/MoveTo

Ad

Answer this question