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

How do I stop a cloned part from being positioned on top of a part?

So, when I clone a part, I want to position it inside of a part. Instead, it positions it on top of the part that's supposed to be positioned to.

Here's my script:

local tool = script.Parent.Parent
local player = game.Players.LocalPlayer
local hum = player.Character:WaitForChild("Humanoid")
local animation = game.ServerStorage.Anime
local blackthings = game.ServerStorage.Model.Part

local db = false
tool.Equipped:connect(function(a)
	for _,v in pairs(tool:GetChildren()) do
		v.Transparency = 1
	end
	a.Button1Down:connect(function()
		if not db then
			db = true

			animation.AnimationId = "http://www.roblox.com/asset/?id=1575109264"
			local animTrack = hum:LoadAnimation(animation)
			animTrack:Play()
			for _,v in pairs(tool:GetChildren()) do
				v.Transparency = 0
				a = 0
				repeat
				local blackthingsClone = blackthings:Clone()
				blackthingsClone.Parent = v
				blackthingsClone.CFrame = CFrame.new(v.CFrame)
				a = a + 1
				print(a)
				until a == 10
				wait()
			end
			wait(5)
			db = false
		end
	end)
end)

5 comments

0

It's just physics, the cloned part(or the generated one) can't be with "can collide" to don't let this happen!

0

the thing is, cancollide is turned off. also, it teleports into the ground

0

You could use CFrame instead. It pretty much ignores parts, unlike Vector3.

0

How could I use CFrame? Can you explain for me please?

0

Give me a second to make an answer.

2 answers

✓ Accepted answer

So Vector3 is like positioning a part but with collisions, CFrame for me is the same thing but with no collisions.

On line 23, you’re changing the position, but you want it to go in a part. This is what you would do using CFrame :

blackthingsClone.CFrame = CFrame.new(v.CFrame)

Think of .CFrame as .Position, and replace Vector3.new with CFrame.new. The part should go in the other part with no problems.

11 comments

0

it says "00:53:37.843 - Players.GIassWindows.Backpack.Tool.Handle.LocalScript:25: bad argument #1 to 'new' (Vector3 expected, got CFrame)"

0

Did you put line 23 exactly like the one I said? No .Position or Vector3 anywhere?

0

no .Position or Vector3. I replaced it with CFrame

0

Can you edit your question with the script you have now then? I need to see what’s wrong. :I

0

Edited

0

It should work. Actually, can you put the “blackthings” in ReplicatedStorage and change line 5? Localscripts can’t access ServerStorage.

0

Oh, and try changing the v.CFrame back into v.Position. The error says it’s expecting a Vector3 value instead? Sorry for making this complicated.

0

Hey! It worked! Thank you so much for helping me, this has been a problem for me for ages!

0

Also, how would I do that with a model?

0

:SetPrimaryPartCFrame() if you want to move a whole model using CFrame. Also make sure to set a PrimaryPart. It’s a property in the model.

0

Thanks dude!

I would try anchoring the part like this:

local part = Part:Clone().Parent = -- Location

part.Anchored = true

You could also try turning CanCollide off:

part.CanCollide = false

3 comments

0

i want it to clone into it then fall out. but it spawns about 3 - 5 studs above it.

0

I also turned cancollide off

0

Then just re position the part after it clones. Use the wait function to to this.

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