When using vector force, parts disappear?

This code is being made in an attempt to make a fluid sim.
The issue is I expect the particles to be pushed away from each other. Instead they just disintegrate on spawn?

Size = {2,2,2}
PreviousPosition = Vector3.new(0,0,0)--Also effects starting position
ParticleNumber = 0

for i = 1,Size[3],1 do
	for i = 1,Size[2],1 do
		for i = 1,Size[1],1 do
			Particle = Instance.new("Part")
			Particle.Shape = "Ball"
			Particle.Size = Vector3.new(1,1,1)
			Particle.Anchored = true
			Particle.Position = Vector3.new(PreviousPosition.X + 1, PreviousPosition.Y, PreviousPosition.Z)
			Particle.Parent = game.Workspace.Simulation.Particles
			
			Particle.Name = tostring(ParticleNumber)
			ParticleNumber += 1
			
			Attachment = Instance.new("Attachment")
			Attachment.Parent = Particle
			
			VectorForce = Instance.new("VectorForce")
			VectorForce.Force = Vector3.new(0,0,0)
			VectorForce.Name = "Force"
			VectorForce.Attachment0 = Attachment
			VectorForce.Parent = Particle

			PreviousPosition = Particle.Position
		end
		PreviousPosition += Vector3.new(0,1,0)
		PreviousPosition = Vector3.new(0,PreviousPosition.Y,PreviousPosition.Z)
	end
	PreviousPosition += Vector3.new(0,0,1)
	PreviousPosition = Vector3.new(PreviousPosition.X,0,PreviousPosition.Z)
end

Particles = game.Workspace.Simulation.Particles:GetChildren()
wait(10)
for i,v in pairs(Particles) do
	v.Anchored = false
end

local RunService = game:GetService("RunService")
RunService.Stepped:Connect(function()
	for i,v in pairs(Particles) do
		local CurrentName = v.Name
		for i,j in pairs(Particles) do
			local PositionOne = v.Position
			local PositionTwo = j.Position

			local X1 = PositionOne.X
			local Y1 = PositionOne.Y
			local Z1 = PositionOne.Z

			local X2 = PositionTwo.X
			local Y2 = PositionTwo.Y
			local Z2 = PositionTwo.Z

			local Distance = math.round(math.sqrt((X2-X1)^2 + (Y2-Y1)^2 + (Z2-Z1)^2) * 100) /100 

			if Distance <2 then	

				local Constant = 10
				local Factor = 1

				local Multiplier = Constant*Distance^-Factor
				local LookAt = (PositionOne - PositionTwo).Unit
				local PushValue = LookAt --* Multiplier
				
				v:FindFirstChild("Force").Force = PushValue

			end
		end
	end
end)
1 Like

Solved, I needed to remove a vector 3. damn

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.