I am trying to make a tool that duplicates a model then moves the duplicate to Workspace. Here is what I have:
01 | local tool = script.Parent |
02 | local clickEvent = tool.ClickEvent |
03 | local spawnblock = game.Workspace.spawnblock |
04 | local clickEventConnection |
05 |
06 | local function createPart(location) |
07 | local work = game.Workspace |
08 | local car = game.ReplicatedStorage.Assets.Car |
09 | local newCar = car:Clone() |
10 | car:Clone() |
11 | newCar.Name = "Car" |
12 | car.Parent = work |
13 | car:MakeJoints() |
14 | car:MoveTo(spawnblock.Position) |
15 | newCar.Parent = game.ReplicatedStorage.Assets |
Here is a local script with the rest of the code:
01 | local tool = script.Parent |
02 | local player = game.Players.LocalPlayer |
03 | local mouse = player:GetMouse() |
04 | local clickEvent = tool.ClickEvent |
05 |
06 | local function onActivate() |
07 | local clickLocation = game.Workspace.spawnblock |
08 | clickEvent:FireServer(clickLocation) |
09 | tool:Remove() |
10 | end |
11 |
12 | tool.Activated:connect(onActivate) |
01 | local tool = script.Parent |
02 | local clickEvent = tool.ClickEvent |
03 | local spawnblock = game.Workspace.spawnblock |
04 | local clickEventConnection |
05 |
06 | local function createPart(location) |
07 | local car = game.ReplicatedStorage.Assets.Car |
08 | local newCar = car:Clone() |
09 | newCar.Name = "Car" |
10 | newCar.Parent = game.Workspace |
11 | newCar:MakeJoints() |
12 | newCar:MoveTo(spawnblock.Position) |
13 | end |
14 |
15 | local function onClick(player, clickLocation) |
This should be it, :)
01 | local tool = script.Parent |
02 | local clickEvent = tool.ClickEvent |
03 | local spawnblock = game.Workspace.spawnblock |
04 | local clickEventConnection |
05 |
06 | local function createPart(location) |
07 | local work = game.Workspace |
08 | local car = game.ReplicatedStorage.Assets.Car:Clone() --Clone it instantly! It will already get cloned. |
09 | car.Parent = work |
10 | car:MakeJoints() |
11 | car:MoveTo(spawnblock.Position) |
12 | car.Archivable = true |
13 | end |
14 |
15 | local function onClick(player, clickLocation) |
The way I was able to fix it was by changing the method you are using to detect a click! A tool has an event called activated so if you connect that it seems to work fine!
01 | local tool = script.Parent |
02 | local spawnblock = game.Workspace.spawnblock |
03 |
04 | local function createPart(location) |
05 | local work = game.Workspace |
06 | local car = game.ReplicatedStorage.Assets.Car:Clone() |
07 | car.Parent = work |
08 | car:MakeJoints() |
09 | car:MoveTo(spawnblock.Position) |
10 | car.Archivable = true |
11 | end |
12 |
13 | local function onClick(player, clickLocation) |
14 | createPart(clickLocation) |
15 | end |