Parts gathering up in one spot?

Hey there! So, i found this post and it didn’t work (not even surprised i mess up everything xd)

What happens rather than the yellow parts going around the blue part, they merge into one and one yellow part just goes to 0,0,0 for some reason.

here is the script (bluep = blue part, part = part thats gonna rotate around blue part):

				for i, v in pairs(parts) do
					local angle = i * (fullCircle / #parts)
					local x, z = getXAndZPositions(angle)
					
					part.Pos.Value = (bluep[plr].Position + Vector3.new(x, 3, z))
				end
				
				local s,e = pcall(function()
					print(part.Pos.Value)
					bodyPos.Position = (part.Pos.Value) - Vector3.new(0,2,0) + Vector3.new(0,part.PrimaryPart.Size.Y/2,0) + Vector3.new(0, 0, 0)
					bodyGyro.CFrame = bluep[plr].CFrame
				end)

(I wrapped in a pcall because it errored everytime i removed the part so i decided to wrap it in a pcall instead cuz sure, the error didnt affect anything, but it was bugging me)

here is what’s happening:
image

yellow parts are merging into one position and blue part is where they are supposed to circle on.

Thanks!

2 Likes

Can you say exactly what you need done. Do you need the yellow parts going around the blue one?

1 Like

Yeah, i need the yellow parts to go around the blue part. It just doesn’t work and they all merge into one position somehow

sorry late reply :sweat_smile:

1 Like
part.Pos.Value = (bluep[plr].Position + Vector3.new(x, 3, z)

Is part defined within scope of this code (globally, or on lines not shown) and has it got a Value Instance named “Pos” as a child? If it is then you are changing this value as many times as the number of items in the “parts” table. But then not doing anything with those values because the loop ends.

If the part.Pos.Value inside the loop is supposed to be referencing a part in the parts table then you have to use the v in the loop header instead to change it because that is what you have named your value in the loop header. i.e.

for i, v in pairs(parts) do
	-- rest of code removed for clarity
	v.Pos.Value = (bluep[plr].Position + Vector3.new(x, 3, z));
end

The function below that you wrapped in a pcall will cause a segmentation fault if part.Pos.Value is not globally defined,i.e. it doesn’t exist in scope. This function is also being called outside the loop so bodyPos and bodyGyro are being changed only once after the loop that changed the value several times has ended.

local s,e = pcall(function()
	print(part.Pos.Value)
	bodyPos.Position = (part.Pos.Value) - Vector3.new(0,2,0) + Vector3.new(0,part.PrimaryPart.Size.Y/2,0) + Vector3.new(0, 0, 0)
	bodyGyro.CFrame = bluep[plr].CFrame
end)

Also if part is a part and not a model then it wont have a PrimaryPart property unless you have created an object with a Size property as a child inside part and named it “PrimaryPart”. You are also adding an empty Vector3 at the end of the line.

Vector3.new(0,part.PrimaryPart.Size.Y/2,0) + Vector3.new(0, 0, 0)

More code would help to see if there any other possible causes, like bluep[plr], I assume this is a table keyed with Players?. Also do you have “Debug Errors” set to “On All Exceptions” in the SCRIPT tab in Studio? It may shine some light on things if you don’t have it set.

I did adapt the code in the link you sent to do this, but you may want to change your code rather than use mine. I can share it with you if you like. Video below shows it working (the jerkiness of the movement is down to the video, it doesn’t do that for real).

1 Like

First of all, WOW thank you for this.

Now to answer your questions;

Yes

It has a number value called “Pos”

Part is a model, i just decided to name it that for some reason.

bluep[plr] is yes, a table keyed with players.

I’ll try that when i get my hands on studio as pc isn’t working right now. (Will tommorow or in a few hours)

That would be great example if i want to fix my script.

Again, thank you for this monstrosity of a post!

1 Like

No problem, glad to help. I uploaded the place file so you can just run it and change it however you want.

Happy coding…

PartMove_Baseplate.rbxl (39.5 KB)

1 Like

Thanks so much! :smiley:

also, since you asked for the script I was using

here it is (ill explain lines)

local function followPart(plr,fpart,char,pid)

plr is player
fpart is the part model
char is character
pid is part id (used for verification, unimportant here)

	local part= fpart:Clone()
	local parts = {}

part is the part’s model clone
parts is the table

	local function getXAndZPositions(angle)
		local x = math.cos(angle) * radius
		local z = math.sin(angle) * radius
		return x, z
	end

from the post

	for _, v in pairs(char:GetChildren()) do
		if v:FindFirstChild("Verification") then
			table.insert(parts,v)
		end
	end
	
	char.ChildAdded:Connect(function(child)
		if child:FindFirstChild("Verification") then
			table.insert(parts,child)
		end
	end)

adding to table

local bodyPos = Instance.new("BodyPosition",part.PrimaryPart)
		bodyPos.MaxForce = Vector3.new(math.huge,math.huge,math.huge)

		local bodyGyro = Instance.new("BodyGyro",part.PrimaryPart)
		bodyGyro.MaxTorque = Vector3.new(math.huge,math.huge,math.huge)

creating the bodyPos and bodyGyro

while task.wait() do
			if part and pause[plr] == false then

loop and if pause[plr] is true then we move the parts around the player, if not then dont.

for i,v in pairs(parts) do
					local angle = i * (fullCircle / #parts)
					local x, z = getXAndZPositions(angle)
					
					bodyPos.Parent = v.PrimaryPart

					bodyGyro.Parent = v.PrimaryPart
					
					local s,e = pcall(function()
						part.PrimaryPart.Position = bluep[plr].Position + Vector3.new(x, 1, z)
					end)
				end


I fixed a bug that kept positioning the part somewhere else, i found out like 5 hours later that its because of the body position i created, i didnt remove the body position before and after i set the cframe so both of them were moving the part.

and yes, i did change the script while the post was going on. script was edited before your post.

this post

thanks!

2 Likes