[Unsolved] Cloning objects on top of each other

Background Information: I have created a system where when a player clicks, it adds a head on top of the original head and the heads keeps cloning on top of each other until they’ve reached a certain limit. My solution to making that was just for every time an Event was fired, it clones the head, and places that cloned head with the position being (0, 1*(the amount of clicks, 0) so the heads don’t merge with each other.

Problem: What I’m now trying to make is so that the cloning and position of the heads don’t have to be multiplied by 1 and the and the amount of clicks because since I added multipliers that add more numbers to the “Heads” value.

For example: Currently if I clone 1 head, it adds 1 stud to the original head position * the amount of heads (aka clicks) the game shows. So if I had 10 heads (clicks) it would position the new head 1*10 + original head position.

What I’m trying to achieve: Every time the number of Heads (clicks) goes up, it clones the same amount of heads that the Heads value received (if 5 was added to the value at once, 5 heads get cloned on top of each other).

I just want to make a system where the number of cloned heads is equivalent to the value of Heads (clicks).

I know this is a long post but I felt like I had to try and explain everything in detail all at once. Thank you for your time.

2 Likes

Use formula thingy

NewPart.Position = Vector3.new(OldPart.Position.X, OldPart.Position.Y + (OldPart.Size.Y + (OldPart.Size.Y / 2)), OldPart.Position.Z)

So I tried this script and I think I did it wrong…

event.OnServerEvent:Connect(function(player)
	local char = player.Character
	local head = char:WaitForChild("Head")

	h.Value += 1*m.Value

	local c = head:Clone()
	c.CanCollide = false
	c.Name = player.Name.."Head"
	--c.Position = head.Position + Vector3.new(0, 1*h.Value, 0)

	c.Position = Vector3.new(head.Position.X, head.Position.Y + (head.Size.Y + (head.Size.Y / 2)), head.Position.Z)

	local weld = Instance.new("WeldConstraint")
	weld.Parent = c
	weld.Part0 = c
	weld.Part1 = head
end)

This spawns a head above the original head but slightly more above than actually touching the head and it doesn’t make the cloned heads stack up. I think it’s because I put in the wrong variables but can you check my script and tell me what I did wrong.

1 Like
local LastCreatedpart = instance.new("Part", workspace)

local function AddAnotherPartOnTop(LastPart)
local NewPart = instance.new("Part",workspace)

NewPart.Position = Vector3.new(LastPart.Position.X, LastPart.Size.Y, LastPart.Position.Z)
end

This was not tested because I’m on phone but I think you get what I mean

I would help you more in depth but I do not understand your problem clearly

2 Likes

Info: “Heads” in this case are clicks renamed

So the problem I’m having is that I’ve been using a cloning system where a head gets added every time someone clicks. Except the way I’m stacking them is adding 1 stud to the y axis and multiplying that by the amount of clicks a player has.

	c.Position = head.Position + Vector3.new(0, 1*h.Value, 0)

c is the cloned part
head is the original head
h is the amount of “Heads” the player has

I found this to be unreliable because I added a head multiplier and when I did that, it skipped heads. For example, I click once and get 2 “Heads”. The game will clone only 1 head but place it 2 studs above the original head because of the script used to position the heads.

Now I’m trying to make it so that the game clones the exact same amount of heads that was added to the players stats.

For example:
A player clicks once and gets 5 Heads (clicks)
The player gets 5 heads that are stacked together added onto their character above the original head or any cloned head that already exists.

1 Like

You could try using a normal weld instead of a constraint one

local weld = Instance.new("Weld")
weld.Parent = c
weld.Part0 = c
weld.Part1 = head
weld.C0 = CFrame.new(0, 1*h.Value, 0)

let me know if this code works

1 Like

HMMMMMMMMM yes.

This works I guess but what I’m trying to achieve is the ability to clone things even when it’s in increments. Like if 5 Heads were added at once, I want it so that 5 heads get cloned on top of each other but this only adds 1 head for every 5 heads.

This is an example picture of what happens (I applied a x5 multiplier)
Screen Shot 2022-08-10 at 10.54.41

The increment problem might speak from itself as I don’t think you are creating heads relative to the multiplier but rather do one head, the multiplier only positions it. If you get what I mean. The solution to this is simply making a for loop with said increment so each head gets created. And you will need a second iteration to get the right values for all heads since for instance: 5 would be the last position, you would need 4,3,2,1 to position each head correctly.