hi! i ran into a problem where some of my created parts are missing.
So basically i have this worm script which follows the player.
when the player press a gui button, it should load 50 segments
but sometimes, the first segments are following the player are expected, but the others are at the end of the world.
here are some pictures and videos of whats happening:
the video shows that after an amount of time, when we click the button again, segments are missing, and im also showing where the missing segments are by looking at the workspace
example of missing segments:


heres the script that adds the worm to the player:
local RS = game:GetService("RunService")
local IKFramwork = require(script.framework)
local segAmount = 50
local PhysicsService = game:GetService("PhysicsService")
local obstacles = "obstacles"
local pass = "pass"
PhysicsService:CreateCollisionGroup(obstacles)
PhysicsService:CreateCollisionGroup(pass)
PhysicsService:CollisionGroupSetCollidable(pass, obstacles, false)
local rm = game.ReplicatedStorage.worm.addWorm
local db = false
rm.OnServerEvent:Connect(function(player)
local function addWormVIP()
local folder = Instance.new("Folder", workspace)
folder.Name = player.Name.."'s Worm"
local character = player.Character or player.CharacterAdded:Wait()
for i,v in pairs(character:GetDescendants()) do
if v:IsA("BasePart") then
PhysicsService:SetPartCollisionGroup(v, pass)
v.Transparency = 1
else
if v:IsA("Decal") then
v.Transparency = 1
end
end
end
local start = Instance.new("Part", folder)
start.Name = player.Name.."'s followPart"
start.Transparency = 1
start.CanCollide = false
start.Anchored = false
start.Massless = true
start.CFrame = character.HumanoidRootPart.CFrame
PhysicsService:SetPartCollisionGroup(start, obstacles)
local weld = Instance.new("Weld", start)
weld.Part0 = start
weld.Part1 = character.HumanoidRootPart
weld.C0 = CFrame.new(0,2,0)
local finish = start
local function makeWormSegments(firstSegment, numberOfSegments)
local maxArmReach = segAmount
local segments = {}
local sizeOfEachSegment = maxArmReach/numberOfSegments
for i = 1, numberOfSegments do
local segment = Instance.new("Part")
segment.Shape = "Ball"
segment.Material = "SmoothPlastic"
segment.Anchored = true
segment.CanCollide = false
segment.Massless = true
segment.Size = Vector3.new(9,9,9)
segment.BrickColor = character:WaitForChild("Head").BrickColor
segment.Name = "segment "..i
segment.CFrame = firstSegment.CFrame * CFrame.new(0,0, -(firstSegment.Size.Z + sizeOfEachSegment * (i-1)))
segment.Parent = folder
PhysicsService:SetPartCollisionGroup(segment, obstacles)
local attachment = Instance.new("Attachment", segment)
attachment.Orientation = Vector3.new(90,0,0)
local fire = Instance.new("Fire", attachment)
fire.Color = character:WaitForChild("Head").Color
fire.Size = 30
table.insert(segments, segment)
end
local segSecond = folder:FindFirstChild("segment 2")
segSecond.Size = Vector3.new(8,8,8)
local segFirst = folder:FindFirstChild("segment 1")
segFirst.Size = Vector3.new(7,7,7)
local segBeforeLast = folder:WaitForChild("segment "..segAmount - 1)
segBeforeLast.Size = Vector3.new(8,8,8)
local segLast = folder:WaitForChild("segment "..segAmount)
segLast.Size = Vector3.new(7,7,7)
return segments
end
local segments = makeWormSegments(finish, segAmount)
RS.Stepped:Connect(function()
IKFramwork.SolveIK(segments, start, finish)
end)
local humanoid = character:WaitForChild("Humanoid")
humanoid.WalkSpeed = humanoid.WalkSpeed * 2
humanoid.JumpHeight = humanoid.JumpHeight * 2
humanoid.AutoJumpEnabled = false
local animate = character:WaitForChild("Animate")
animate:Destroy()
local newAnimate = game:GetService("ReplicatedStorage").player.Animate:Clone()
newAnimate.Parent = character
character.Humanoid.Died:Connect(function()
folder:Destroy()
end)
end
-- add worm
addWormVIP()
rm:FireClient(player)
end)
heres the module that scripts the framework of the worm:
local IKFramwork = {}
function IKFramwork.SolveIK(segments, startPart, endPart)
local prevSegment = nil;
for i = #segments, 1, -1 do
local goalPosition;
local currentSegment = segments[i];
if (not prevSegment) then
goalPosition = endPart.Position
else
goalPosition = (prevSegment.CFrame * CFrame.new(0,0,prevSegment.Size.Z/3)).p
end
local startPositionOfThisSegment = (currentSegment.CFrame * CFrame.new(0,0,currentSegment.Size.Z/3)).p
currentSegment.CFrame = (CFrame.new(goalPosition, startPositionOfThisSegment) * CFrame.new(0,0,-currentSegment.Size.Z/3)) * CFrame.Angles(0,math.pi,0)
prevSegment = currentSegment
end
end
return IKFramwork