Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Question: How to Clone a Touched Part [?]

local CloneVehicle = hit.Parent
local ClonedVehicle = CloneVehicle:Clone()


script.Parent.Touched:Connect(function(hit) 
	if hit.Parent.Name == "RedRectangleVehicle" then
	    ClonedVehicle.Position = Vector3.new(-1093.61, 0.5, -5.75)
	    ClonedVehicle.Parent = workspace
	end
end)

How to clone a touched part? What have I mistaken in my code? I used PrimaryPart script to move my vehicle.

10 comments

0

Have you tried ClonedVehicle.CFrame = CFrame.new(-1093.61, 0.5, -5.75)

0

You mean teleporting the vehicle? I was thinking about that. Ill try later.

0

Also, your CloneVehicle would be nil as as you have not set it to the parts name. You need to set the name like something “CloneVehicle = YOURTEXTHERE”

0

Ok

0

I don't understand. Also what is nil? I have no idea what is that.

0

Ok nil is zero

0

I thought: game.Workspace.RedRectangleVehicle:MoveTo(Vector3.new(-1098.925, 0.5, -5.34) will fix the problem. But It does nothing.

0

script.Parent.Touched:connect(function(hit) if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then script.Parent:Clone() end end) Ths will dupe the part that is touched if touched by player

0

Your problem is actually that you're cloning the object in the beginning, you need to set the ClonedVehicled variable inside the function, so you clone it each time

0

you should try using :Clone() bc thats how you clone stuff. for example if i want to clone a block i would use part touched function then make it detect for humanoid then if there is one workspace.NAME:Clone(). NAME.Parent.Head.Position (IF U WANT IT ON AN NPC)

3 answers

I’d recommend using something like this.

local CloneVehicle = “nil”
local ClonedVehicle = CloneVehicle:Clone()

function Touched(hit)
    if hit.Parent.Name == “ RedRectangleVehicle” then
         CloneVehicle = hit.Parent.Name
         ClonedVehicle.PrimaryPart.CFrame = CFrame.new(-1093.61, 0.5, -5.75)
         wait(5)
         ClonedVehicle.Parent = game.Workspace
end)

script.Parent.Touched:Connect(Touched)

I wrote this on phone so, there might be errors.

script.Parent.Touched:Connect(function(hit) 
    if hit.Parent.Name == "RedRectangleVehicle" then
        local Cloned = hit.Parent:Clone()
	Cloned.PrimaryPart = Clone:FindFirstChild("Center")
	Cloned:SetPrimaryPartCFrame(CFrame.new(-1093.61, 0.5, -5.75))
	Cloned.Parent = workspace
    end
end)

Hey. Here's how you do that:

function onTouch(hit)
     if hit.Parent.Humanoid ~= nil then
        script.Parent:Clone()
   end
end

script.Parent.Touched:Connect(onTouch)

Tell me if it worked! If so please upvote me^

This discussion is preserved as it was. New answers, comments, and votes are closed.