Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I make this script check the workspace for any part named 'window' every 300 seconds?

Asked by 7 years ago
Edited 7 years ago

How can I make this script check the workspace for any part named 'window' every 300 seconds and change the transparency to 0 and the cancollide to false?

I've tried this already.

while true do
wait(300)
a = game.Workspace:getChildren(game.Workspace)
if a.Name == "Window" then
a.Transparency = 0
a.Cancollide = false
end

2 answers

Log in to vote
3
Answered by
RayCurse 1518 Moderation Voter
7 years ago
Edited 7 years ago

The GetChildren() function returns all the children of the instance it is called on packaged in a table. If you want to search for any part named "Window", then you would iterate or go over the table returned by the GetChildren function. Iterating is usually done with a generic for loop which is implemented below. On every iteration the script checks if the current child is a window and if so, changes the Transparency and CanCollide properties.

while true do
    wait(300)
    children = game.Workspace:GetChildren()
    for _ , a in pairs (children) do
        if a.Name == "Window" then
            a.Transparency = 0
            a.CanCollide = false
        end
    end
end
1
One important thing to note is that :GetChildren() returns only the immediate children. You can use :GetDescendants() which basically returns the children of the children just in case a window is in a model that is a child to workspace. Ultimate_Piccolo 201 — 7y
Ad
Log in to vote
-1
Answered by 7 years ago

try use findFirstChild, i think this is the ebst way to do it

Answer this question