Help with cloning

Hi,

Im trying to make a part be cloned from replicated storage. How do I make it so when you touch a part it clones a part?

I only have the clone part done and not the touch function done.

local Buy = script.Parent
local Object = game.ReplicatedStorage.Object
local CloneObject = Object:Clone()

CloneObject.Parent = game.Workspace
CloneObject.Name = "Object"

From,
File

1 Like

also inside of the script I aim unaware when it calls to clone the part.

Hey, firstly, there is no need to write posts as if you were writing an e-mail. Just try to make your topic clear for us to understand. Secondly, there are several methods to achieve what you want, each with their pros and cons. For the general case, I’d recommend using a event which can be used to track collision between one part and other, which is what the BasePart.Touched event can accomplish.

However, this event can be fired multiple times incredibly quickly, which requires the need of a Debounce.

Here’s some source code for you to analyze and test:

local Buy = script.Parent
local Object = game.ReplicatedStorage.Object

-- I assume "Buy" is a BasePart
Buy.Touched:Connect(function(hit)
    if (not game:GetService("Players"):GetPlayerFromCharacter(hit)) then
        return;
    end

    local CloneObject = Object:Clone();
    CloneObject.Parent = game.Workspace; -- Cloning an Instance overrides its Parent, so it is needed to declare it later.
end)

Sources:

BasePart.Touched (roblox.com)

1 Like

Assuming this script is inside the Buy variable:

local BuyPart = script.Parent
local Object = game.ReplicatedStorage:WaitForChild("Object")
local Player = game:GetService("Players").LocalPlayer

local Clone = Object:Clone()
Clone.Parent = game.ReplicatedStorage

BuyParent.Touched:Connect(function(hit)
     if hit.Parent == Player.Character then
     Clone.Parent = game.Workspace
end)

Let me know if I did something wrong or you need the code made differently!

This script would be incorrect, due to it being the Touched event only. When the part is Touched, it will fire the event. You would need to find if the event is touched by a Character, or it will fire from anything!

Reading above, it stated…

Im trying to make a part be cloned from replicated storage. How do I make it so when you touch a part it clones a part.

Assure you fully understand what they mean. You would mean the player! (:

1 Like

Though LocalScripts don’t work in Workspace unless they are parented to a character. How about that?

There is also a minor typo in your script.

Also what’s with that much spoon-feeding?

I could easily turn it into a LocalScript script if needed, however it is undetermined if they need a LocalScript or ServerScript.

The script doesn’t work and clones the part to replicated not workspace. It also clones the part before I could step on buy.

Very well, thanks for telling me! I will create a new one for you! I will send you the model once done. :smiley:

actually its okay. I finished the script by tweaking yours a bit. You still deserve full credit.

local BuyPart = script.Parent
local Object = game.ReplicatedStorage:WaitForChild("Object")
local Player = game:GetService("Players").LocalPlayer

BuyPart.Touched:Connect(function(hit)
	local Clone = Object:Clone()
	Clone.Parent = game.Workspace
	if hit.Parent == Player.Character then
		Clone.Parent = game.Workspace
	end
end)

Thank you! If you ever need more help, reach out to me! Have a fantastic day/night! <33