this script always crashes my game when i solo test but i dont know why and where it crashes
this is the script that crashes the game
local plrs = {game.Workspace.Model}
local parts = {game.Workspace.TestTableThing}
local Region = Region3.new(script.Parent.Parent.PrimaryObject.Position - Vector3.new(160,160,160), script.Parent.Parent.PrimaryObject.Position + Vector3.new(160,160,160))
local pArTsSs = Instance.new("Part", game.Workspace)
pArTsSs.Name = "RegionPart"
pArTsSs.CFrame = Region.CFrame
pArTsSs.Anchored = true
pArTsSs.CanCollide = false
pArTsSs.Transparency = 1
function PresentInTable(player)
local IsIn = false
for i, v in pairs(plrs) do
if v == player then
IsIn = true
end
end
return IsIn
end
function PartInTable(part)
local IsInside = false
for i, v in pairs(parts) do
if v == part then
IsInside = true
end
end
return IsInside
end
local parts = game.Workspace:FindPartsInRegion3(Region, pArTsSs, 1000)
for i, v in pairs(parts) do
if v.Parent:FindFirstChild("Humanoid") and v.Parent:FindFirstChild("HumanoidRootPart") then
if v.Parent:IsA("Model") then
local Value = PresentInTable(v.Parent)
if Value == false then
local Name = script.Parent.Parent:FindFirstChildOfClass("BoolValue")
if v.Parent.Name ~= Name.Name then
table.insert(plrs, v.Parent)
local PartToLook = Instance.new("Part", v.Parent)
PartToLook.Transparency = 1
PartToLook.CanCollide = false
PartToLook.CFrame = CFrame.new(v.Parent.HumanoidRootPart.Position, script.Parent.Parent.PrimaryObject.CFrame.Position)
local Weld = Instance.new("WeldConstraint", PartToLook)
Weld.Part0 = PartToLook
Weld.Part1 = v.Parent.HumanoidRootPart
local Attachment = Instance.new("Attachment", PartToLook)
local Constraint = Instance.new("RodConstraint", PartToLook)
Constraint.Length = (v.Parent.HumanoidRootPart.Position - script.Parent.Parent.PrimaryObject.Position).magnitude
Constraint.Attachment0 = PartToLook.Attachment
Constraint.Attachment1 = script.Parent.Parent.PrimaryObject.Attachment
local BT = Instance.new("BodyThrust", PartToLook)
BT.Force = Vector3.new(-90000,0,0)
local ClonedScript = script.ScriptForHuman:Clone()
ClonedScript.Parent = PartToLook
ClonedScript.Name = v.Parent.Name
ClonedScript.Disabled = false
end
end
end
else
if v.Anchored == false then
local Value = PartInTable(v)
if Value == false then
v:BreakJoints() -- the crashing only happens from here onwards
table.insert(parts, v)
local PartToLook = Instance.new("Part", v)
PartToLook.Transparency = 1
PartToLook.CanCollide = true
PartToLook.CFrame = CFrame.new(v.Position, script.Parent.Parent.PrimaryObject.CFrame.Position)
local Weld = Instance.new("WeldConstraint", PartToLook)
Weld.Part0 = PartToLook
Weld.Part1 = script.Parent.Parent.PrimaryObject
local Attachment = Instance.new("Attachment", PartToLook)
local Constraint = Instance.new("RodConstraint")
Constraint.Length = (PartToLook.Position - script.Parent.Parent.PrimaryObject.Position).magnitude
Constraint.Attachment0 = Attachment
Constraint.Attachment1 = script.Parent.Parent.PrimaryObject.Attachment
local BT = Instance.new("BodyThrust", PartToLook)
BT.Force = Vector3.new(-70000,0,0)
local ClonedScript = script.ScriptForPart:Clone()
ClonedScript.Parent = PartToLook
ClonedScript.Disabled = false
table.insert(parts, PartToLook)
end
end
end
end
the crashing only occurs after the else statement in the for loop for the table of parts in the region. Thank you.
and btw sry for the messy code
I sincerely apologise for the lack of clarity. This is supposed to be a move for a character. When the move is starting, a clone of a tornado model is parented to the workspace with this script inside a part inside the model. The script's disabled property is then set to false. Ive tested it for some time and realised that the game crashes because of the line of code 'table.insert(parts, v)'. No errors are shown in the output as studio crashes. I have another script similar to this one and it lags a lot less and doesnt crash. The only difference is that it does not add a constraint and attachment to the 'PartToLook'.

3 comments
This is not your code. Additionally, you need to provide the errors you are getting and more detail about your problem in the description. Saving you time because I am not the only one confused by your question.
I sincerely apologise for the lack of clarity
I have updated the description and added more detail.