I’m having an issue with starting moveable hitboxes right now. Error : 12:12:41.498 ReplicatedStorage.Modules.VoxBreaker:1231: attempt to index nil with ‘Part’ - Client - VoxBreaker:1231 .
Here is the localscript that is running VoxBreaker :
local voxBreaker = require(game:GetService("ReplicatedStorage").Modules.VoxBreaker)
local event = game:GetService("ReplicatedStorage").Events.DestructionClient
local function shuffleTable(t)
print("Shuffling table...")
local n = #t
for i = n, 2, -1 do
local j = math.random(i)
t[i], t[j] = t[j], t[i]
end
end
local function onEvent(player, force, velocityTime, size, cframe, shape, minimumVoxelSize, destroyPercent, weldToPart)
print("Received destruction event for player:", player.Name)
if not weldToPart or weldToPart == nil then
local character = player.Character
local parts = voxBreaker:CreateHitbox(size, cframe, shape, minimumVoxelSize)
print("Created hitbox parts:", #parts)
-- Create a table of indices and shuffle it
local indices = {}
for i = 1, #parts do
table.insert(indices, i)
end
shuffleTable(indices)
-- Destroy 50% of the parts
local destroyCount = math.floor(#parts / destroyPercent)
print("Destroying", destroyCount, "parts out of", #parts)
for i = 1, destroyCount do
local partIndex = indices[i]
parts[partIndex]:Destroy()
print("Destroyed part", i, "with index", partIndex)
end
-- Add BodyVelocity to the remaining parts
for i, v in pairs(parts) do
if v.Parent then -- Check if the part was not destroyed
v.Anchored = false
local bv = Instance.new("BodyVelocity", v)
bv.Velocity = character.HumanoidRootPart.CFrame.LookVector * force
bv.MaxForce = Vector3.new(99999, 99999, 99999)
bv.Name = "Velocity"
game:GetService("Debris"):AddItem(bv, velocityTime)
print("Added BodyVelocity to part:", v.Name)
else
print("Part", v.Name, "was destroyed before adding BodyVelocity")
return
end
end
end
if weldToPart and weldToPart ~= nil then
local character = player.Character
local parts = voxBreaker.CreateMoveableHitbox(minimumVoxelSize, 50, size, weldToPart.CFrame, shape)
parts.Start()
print("started")
parts.WeldTo(weldToPart)
print("welded")
print("Created movable hitbox parts:", #parts)
if not weldToPart.Parent then
parts.Stop()
parts.Destroy()
print("voxelbreaker destroyed early")
end
-- Create a table of indices and shuffle it
local indices = {}
for i = 1, #parts do
table.insert(indices, i)
end
shuffleTable(indices)
-- Destroy 50% of the parts
local destroyCount = math.floor(#parts / destroyPercent)
print("Destroying", destroyCount, "parts out of", #parts)
for i = 1, destroyCount do
local partIndex = indices[i]
parts[partIndex]:Destroy()
print("Destroyed part", i, "with index", partIndex)
end
-- Add BodyVelocity to the remaining parts
for i, v in pairs(parts) do
if v.Parent then -- Check if the part was not destroyed
v.Anchored = false
local bv = Instance.new("BodyVelocity", v)
bv.Velocity = character.HumanoidRootPart.CFrame.LookVector * force
bv.MaxForce = Vector3.new(99999, 99999, 99999)
bv.Name = "Velocity"
game:GetService("Debris"):AddItem(bv, velocityTime)
print("Added BodyVelocity to part:", v.Name)
else
print("Part", v.Name, "was destroyed before adding BodyVelocity")
return
end
end
end
end
event.OnClientEvent:Connect(onEvent)
print("Connected onEvent function to client event:", event.Name)
Does anyone have any ideas on how to fix?
EDIT: YOU CAN FIX IT BY DOING
parts:Start()
parts:Stop()
parts:Destroy()
--Instead of doing
parts.Start()
parts.Stop()
parts.Destroy()