Okay, so I am trying to make a script that disables collision on windows to prevent a bit of lag, now I have the script except it just looks threw workspace with only finds 1. The rest of the windows are in separate models how do I get every single one of them?
local Workspace = game.Workspace
for i, v in pairs(Workspace:GetChildren()) do
if v.Name == ("Window") then
coroutine.wrap(function()
for i = 0, 1, .2 do
print("Found window")
v.CanCollide = false
v.CanTouch = false
wait(.5)
end
end)()
end
end
for i, v in pairs(Workspace:GetDescendants()()) do
if v.Name == ("Window") then
coroutine.wrap(function()
for i = 0, 1, .2 do
print("Found window")
v.CanCollide = false
v.CanTouch = false
wait(.5)
end
end)()
end
end
for i,v in pairs(workspace:GetDescendants()) do
if v.Name == "Window" and v:IsA("BasePart") then
v.CanCollide = false
v.CanTouch = false
end
end
Or you can use this, same thing just scans the Academy folder instead of Workspace:
for i,v in pairs(workspace.Academy:GetDescendants()) do
if v.Name == "Window" and v:IsA("BasePart") then
v.CanCollide = false
v.CanTouch = false
end
end
Thanks, but what about if the model is named “Window” but I want the parts inside no collide too, some are parts named Windows and some are models with parts and union
I would suggest using the Collection service for this along with a neat plugin called Tag Editor to mark the objects you want to access, would make the process easier.
for i,v in pairs(workspace:GetDescendants()) do
if v.Name == "Window" and v.ClassName == "Model" then
for i,v in pairs(v:GetDescendants()) do
if v:IsA("BasePart") then
v.CanCollide = false
v.CanTouch = false
end
end
end
end
This just finds all models in the workspace called Window and then makes all parts inside them noncollidable (doing full-scale workspace scans like this is quite bad practice and it would be better if you just put all the window parts in one folder for efficiency)