For loop doesn't work

Hi! I was trying to loop through a folder to get all the children of that folder but it doesn’t seem to work. Do I have to do anything extra or did I call it wrong?

This script is in StarterGUI and it’s a local script

Here’s the script:

local JanitorBlocker = game.workspace:WaitForChild("JanitorBlockers") -- this is the folder
local TrelloEvent = game:GetService("ReplicatedStorage"):WaitForChild("TrelloEvent")

TrelloEvent.OnClientEvent:Connect(function(Player)
	--this works but only for a single part
	game.workspace:WaitForChild("JanitorBlockers"):WaitForChild("Janitor").CanCollide = false
	
	--this loop would not work
	for _, areas in pairs(JanitorBlocker:GetChildren()) do
		print(areas)
		areas.CanCollide = false
	end
end)

Helps are appreciated!

Can you send a screenshot of the output?

It works for me but not for others for some reason…It seems to be printing everything fine

The other person’s output:
image

It works only for you, since it’s in a LocalScript, which works for only one player

I forgot to mention. I did a remote event through a server script, my bad.

local JanitorBlocker = game.workspace:WaitForChild("JanitorBlockers") -- this is the part that blocks the player from the janitor area



local TrelloEvent = game:GetService("ReplicatedStorage"):WaitForChild("TrelloEvent")
local TrelloAPI = require(game.ServerScriptService:WaitForChild("TrelloAPI"))
local BoardID = TrelloAPI.BoardsAPI.GetBoardID("Sector Leads")
local ListId = TrelloAPI.BoardsAPI.GetListID(BoardID,"🧹 Dirty Janitors")

game.Players.PlayerAdded:Connect(function(plr)
			for _, JanitorNames in pairs(TrelloAPI.CardsAPI.GetCardsOnList(ListId)) do
				if JanitorNames.name == tostring(plr.UserId) then
					TrelloEvent:FireClient(plr)
				end
			end
	end)

The errors don’t match with what I would assume the issue is, but I would recommend doing something like this:

for _,part in JanitorBlocker:GetDescendants() do
	if part:IsA('BasePart') then
		part.CanCollide = false
	end
end

Which will find every base part, no matter how deep, and set its CanCollide property to false.

1 Like

Put a print command after the TrelloEvent:FireClient(plr) to check if the person passed the trello check. This might be due to issues with the scripts associated with trello or something inputted wrong in the trello.

Yeah that would be a better option if you’re just looking to make the parts’ collisions off.

The code looks like it works fine.
The two outputs seem to print the same janitor blockers, but the second has a bunch of other errors/ warnings.
How many others does this not work for? Could the issue be related to another plugin which doesn’t work for them?

So what doesn’t this do? Does it print everything? Even though you started the code through a remote event from the server you still can’t change sever part’s CanCollide from the client right?

This is another output for MaterialService which i asume doesn’t have to do with anything

I dont think it is an issue with the pluggin, i think its the loop itself

I tried but it still doesnt work, i did put a print in the loop on the client too but nothing.

client:

TrelloEvent.OnClientEvent:Connect(function(Player)
	for _, part in pairs (JanitorBlocker:GetDescendants()) do
		if part:IsA('BasePart') then
			print(part)
			part.CanCollide = false
		end
	end
end)
print("janitor 2")

server: (I implemented @araball222 's idea which is to add a print after it fires and it did

local JanitorBlocker = game.workspace:WaitForChild("JanitorBlockers") -- this is the part that blocks the player from the janitor area



local TrelloEvent = game:GetService("ReplicatedStorage"):WaitForChild("TrelloEvent")
local TrelloAPI = require(game.ServerScriptService:WaitForChild("TrelloAPI"))
local BoardID = TrelloAPI.BoardsAPI.GetBoardID("Sector Leads")
local ListId = TrelloAPI.BoardsAPI.GetListID(BoardID,"🧹 Dirty Janitors")

game.Players.PlayerAdded:Connect(function(plr)
			for _, JanitorNames in pairs(TrelloAPI.CardsAPI.GetCardsOnList(ListId)) do
				if JanitorNames.name == tostring(plr.UserId) then
					TrelloEvent:FireClient(plr)
					print("ServerFired")
				end
			end
	end)

image

It could be the GUI and or parts haven’t loaded before the event fires.
You could add a character added connection on the server before firing the event.

1 Like

Maybe something like this … Just a bit of restructuring.

local JanitorBlocker = game.workspace:WaitForChild("JanitorBlockers")

local TrelloEvent = game:GetService("ReplicatedStorage"):WaitForChild("TrelloEvent")
local TrelloAPI = require(game.ServerScriptService:WaitForChild("TrelloAPI"))
local BoardID = TrelloAPI.BoardsAPI.GetBoardID("Sector Leads")
local ListId = TrelloAPI.BoardsAPI.GetListID(BoardID, "🧹 Dirty Janitors")

game.Players.PlayerAdded:Connect(function(plr)
    for _, JanitorNames in pairs(TrelloAPI.CardsAPI.GetCardsOnList(ListId)) do
        if JanitorNames.name == tostring(plr.UserId) then
            TrelloEvent:FireClient(plr)
        end
    end
end)

Thank you! That might’ve fixed with along with some wait() added. Thank you for your help.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.