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

I am having duplication problems. Why won't this script duplicate? [CLOSED]

Asked by 8 years ago
Edited 8 years ago

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)
0
Turn archivable on! Bertox 159 — 8y

3 answers

Log in to vote
1
Answered by 8 years ago
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, :)

0
OMG THANK YOU SOOOOO MUCH MrMinecraft998887 87 — 8y
Ad
Log in to vote
0
Answered by
Bertox 159
8 years ago
Edited 8 years ago

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)
0
could you put that in a code block MrMinecraft998887 87 — 8y
Log in to vote
0
Answered by 8 years ago
Edited 8 years ago

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)
0
I already have the activated done MrMinecraft998887 87 — 8y

Answer this question