I want to figure out how to get all children inside a parent, but something weird has happened.
Recently I’ve encountered a strange change or bug, and it broke some of my scripts. For example, before Roblox went down, when I type for a, b in pairs(game.Workspace:GetChildren()) do, I expected it to have no errors and get all of Workspace’s Children, and it did just that. After Roblox went back up and when I load my game in Studio and play tested, I found out that some of my scripts containing something similar to for a, b in pairs() do, it gets an error in the Output saying
It seemed like something must have been changed while Roblox was down, or i was unaware of a new update.
Here’s what I’ve typed in my scripts. Here, line 23 is the problem:
Here’s a picture of my script that is supposed to create a LineForce inside all of MeshParts in Workspace and Parent it to ‘a’ (every MeshPart in Workspace), it used to work before but now, but ‘a’ is now number 1 so the LineForce is unable to be Parented because ‘a’ turned into a number.
Thanks for the reply!
I’ve replaced them, and it doesn’t seem to work. I’ve got the same error. I’m unsure, but I think the a and b can be named to anything and they both will have the same information because I’ve also tried naming them to something random after changing the script accordingly.
I’ve also tried workspace[b].Classname but that didn’t seem to change anything so i switched back to the old one.
Here’s the full script if that helps. The script is also placed inside ServerScriptService.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteFunction = ReplicatedStorage:WaitForChild("Spawn")
local function onCreatePart(Player, CamPosition) -- Player's name and their camera position
local newPart = Instance.new("Part")
newPart.Position = CamPosition
newPart.Parent = workspace
for a, b in pairs(game.Workspace:GetChildren()) do
if a.ClassName == "Part" or a.ClassName == "MeshPart" then
local LineForce = Instance.new("LineForce")
LineForce.Attachment0 = a
LineForce.Attachment1 = newPart
LineForce.ApplyAtCenterOfMass = true
LineForce.InverseSquareLaw = true
LineForce.ReactionForceEnabled = true
LineForce.Magnitude = newPart.Size.X * 100
LineForce.Parent = a
end
end
end
remoteFunction.OnServerEvent:Connect(onCreatePart) -- When a client fires to server
You just set the wrong variables, a is the index and b is the object.
I just replaced a with b.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteFunction = ReplicatedStorage:WaitForChild("Spawn")
local function onCreatePart(Player, CamPosition) -- Player's name and their camera position
local newPart = Instance.new("Part")
newPart.Position = CamPosition
newPart.Parent = workspace
for a, b in pairs(game.Workspace:GetChildren()) do
if b.ClassName == "Part" or b.ClassName == "MeshPart" then
local LineForce = Instance.new("LineForce")
LineForce.Attachment0 = b
LineForce.Attachment1 = newPart
LineForce.ApplyAtCenterOfMass = true
LineForce.InverseSquareLaw = true
LineForce.ReactionForceEnabled = true
LineForce.Magnitude = newPart.Size.X * 100
LineForce.Parent = b
end
end
end
remoteFunction.OnServerEvent:Connect(onCreatePart) -- When a client fires to server