Hello, I have written code to group multiple parts using welding constraints and then move them using LinearVelocity.
However, a strange bug occurs. After about 5 minutes of testing, the welded parts stop moving.
What’s even more peculiar is that the LinearVelocity speed continues to be applied, yet the parts do not move.
If you want to check after running the rbxl file I uploaded, you can verify it on the server side in Roblox Studio.
(bug situation)
test.rbxl (56.6 KB)
my code
local serverRoot = Instance.new("Camera")
serverRoot.Name = "serverRoot"
serverRoot.Parent = workspace
local divisionNum = 50
local partCount = 5000
function getGroupInfo(index : number)
assert(index)
local grounpIndex = math.floor((index-1) / divisionNum) + 1
local groupStartNum = (grounpIndex-1) *divisionNum + 1
local grounEndNum = grounpIndex * divisionNum
return grounpIndex, groupStartNum, grounEndNum
end
function createPart(i)
local p = Instance.new("Part")
local att = Instance.new("Attachment")
local lv = Instance.new("LinearVelocity")
lv.ForceLimitsEnabled = false
lv.VectorVelocity = Vector3.new(0,0,0)
lv.Attachment0 = att
lv.Enabled = true
lv.Parent = p
att.Parent = p
local weldConstraint = Instance.new("WeldConstraint")
weldConstraint.Part1 = p
weldConstraint.Parent = p
p.Size = Vector3.new(4,4,4)
p.Shape = Enum.PartType.Cylinder
p.EnableFluidForces = false
local size = p.Size.X + 2
local padding = 0
local groupIndex, startNum , endNum = getGroupInfo(i)
if startNum == i then
padding = 50
p.Color = Color3.fromRGB(255,0,0)
end
local col = ((i - 1) % divisionNum + 1) * size
local row = (math.floor((i-1) / divisionNum) + 1)* size
p.CFrame = CFrame.new(Vector3.new(row, 2, col)) * CFrame.Angles(0,0,math.rad(90))
p.Anchored = true
p.Parent = serverRoot
return p, lv
end
local items = {}
local velocities = {}
for i=1, partCount do
items[i],velocities[i] = createPart(i)
if i%100 == 0 then
task.wait(0)
end
end
local firstItem = items[1]
for i=1, partCount do
local groupIndex, startNum, endNum = getGroupInfo(i)
items[i].WeldConstraint.Part0 = items[startNum]
velocities[i].VectorVelocity = Vector3.new(1,0,0)
if i%100 == 0 then
task.wait(0)
end
end
for i=1, partCount do
items[i].Anchored = false
if i%50 == 0 then
task.wait(0)
end
end
local lastTick = tick()
local currentTick = tick()
local num = 5
local RunService = game:GetService("RunService")
RunService.PreSimulation:Connect(function(delta)
currentTick = tick()
if currentTick-lastTick < 5 then return end
lastTick = currentTick
num = num * -1
for i=1, partCount do
velocities[i].VectorVelocity = Vector3.new(num, 0, 0)
end
end)
(Additionally, I am using a translator to ask questions.
If my English is not fluent, I apologize.)