I am trying to make a tool that duplicates a model then moves the duplicate to Workspace. Here is what I have:
local tool = script.Parent local clickEvent = tool.ClickEvent local spawnblock = game.Workspace.spawnblock local clickEventConnection local function createPart(location) local work = game.Workspace local car = game.ReplicatedStorage.Assets.Car local newCar = car:Clone() car:Clone() newCar.Name = "Car" car.Parent = work car:MakeJoints() car:MoveTo(spawnblock.Position) newCar.Parent = game.ReplicatedStorage.Assets end local function onClick(player, clickLocation) createPart(clickLocation) end local function onEquip() clickEventConnection = clickEvent.OnServerEvent:connect(onClick) end
Here is a local script with the rest of the code:
local tool = script.Parent local player = game.Players.LocalPlayer local mouse = player:GetMouse() local clickEvent = tool.ClickEvent local function onActivate() local clickLocation = game.Workspace.spawnblock clickEvent:FireServer(clickLocation) tool:Remove() end tool.Activated:connect(onActivate)
local tool = script.Parent local clickEvent = tool.ClickEvent local spawnblock = game.Workspace.spawnblock local clickEventConnection local function createPart(location) local car = game.ReplicatedStorage.Assets.Car local newCar = car:Clone() newCar.Name = "Car" newCar.Parent = game.Workspace newCar:MakeJoints() newCar:MoveTo(spawnblock.Position) end local function onClick(player, clickLocation) createPart(clickLocation) end local function onEquip() clickEventConnection = clickEvent.OnServerEvent:connect(onClick) end
This should be it, :)
local tool = script.Parent local clickEvent = tool.ClickEvent local spawnblock = game.Workspace.spawnblock local clickEventConnection local function createPart(location) local work = game.Workspace local car = game.ReplicatedStorage.Assets.Car:Clone() --Clone it instantly! It will already get cloned. car.Parent = work car:MakeJoints() car:MoveTo(spawnblock.Position) car.Archivable = true end local function onClick(player, clickLocation) createPart(clickLocation) end local function onEquip() clickEventConnection = clickEvent.OnServerEvent:connect(onClick) end tool.Equipped:connect(onEquip)
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!
local tool = script.Parent local spawnblock = game.Workspace.spawnblock local function createPart(location) local work = game.Workspace local car = game.ReplicatedStorage.Assets.Car:Clone() car.Parent = work car:MakeJoints() car:MoveTo(spawnblock.Position) car.Archivable = true end local function onClick(player, clickLocation) createPart(clickLocation) end local function onEquip() tool.Activated:connect(onClick) end tool.Equipped:connect(onEquip)