Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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 comment

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.

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

This discussion is preserved as it was. New answers, comments, and votes are closed.