Ad
Log in to vote
0

how do i make a clone of a part from replicated storage to workspace in a certain position?

Asked by 3 days ago

I'm a beginner and i don't really understand some of the other script things but I tried making my own script so that I could learn but it didn't work :(

my script:

local click = script.Parent local button = script.Parent local block = game.ReplicatedStorage.test

click.MouseClick:Connect(function() block = block:Clone() --clones block block.parent = game.Workspace -- clone transfers to the workspace block.Position = Vector3.new(69.971, 38.673, -244.463) --puts it to the location end)

0
Can you put your code in a code block. MarkedTomato 620 — 3d

2 answers

Log in to vote
0
Answered by 3 days ago
Edited 3 days ago

Recommendations

  1. You should always use :GetService even if you can define the service from the DataModel. Why? Because :GetService can still retrieve the service even if you were to change the name. The workspace is different, there's a global variable known as Workspace or workspace.

  2. You should change the properties of an instance first, then the last thing you should do is parent it, this can increase the performance of your game.

Fixed Script

local click = script.Parent 
local block = game:GetService("ReplicatedStorage").test

click.MouseClick:Connect(function(playerThatClicked) 
   local cloneBlock = block:Clone()
   cloneBlock .Position = Vector3.new(69.971, 38.673, -244.463) 
   cloneBlock .Parent = workspace 
end)

Explanation

Removed the button variable because you had two variables that had the same value.

From my POV, the click variable is a ClickDetector. The MouseClick event of the ClickDetector has a parameter which is the PlayerThatClicked.

So, after that, I created a variable for that the cloned Instance. Usually, when I just want to parent it to the workspace, I would do block:Clone().Parent = workspace I would do it in one line, but for this case, you want to change the position so, you have to create a variable.

Then, the last are changing the Position and parenting it.

Also, I'm confused why you created variables that had the same value.

0
Ay man they said they were a beginner bro take it easy and don't use such big words 25MouseSensitivity 38 — 3d
Ad
Log in to vote
0
Answered by 3 days ago
Edited 3 days ago

Alright So I Just Made A Few Fixes But Here You Go:

-- // Variables
local Click = script.Parent 
local Block = game.ReplicatedStorage:WaitForChild('test')

local Position = Vector3.new(69.971, 38.673, -244.463)


local function PlaceMent()
  Block2 = Block:Clone()
  Block2.parent = game.Workspace
  Block.Position =  Position
end


Click.MouseClick:Connect(PlaceMent) 

Answer this question