Script not identifying folder

Tryna make a script which teleports all of the members of a group to it however it doesnt work since it cant identify the folder “Players” when it clearly exists

image

image

image

local Players = game:GetService("Players")
script.Parent.ClickDetector.MouseClick:Connect(function(player)
	local folders = game.ReplicatedStorage.Invites
	local root = player.Character:FindFirstChild("HumanoidRootPart")
	local Workspace = game:GetService("Workspace")
	if root then
		
		game.ReplicatedStorage.JudgementHall.Parent = workspace
		
		root.CFrame = CFrame.new(-2808.753, 1550.77, -3419.949)

		script.Parent.Parent.Parent["J-FIGHT"].Parent = game.ServerStorage

		game.ServerStorage["J-NOFIGHT"].Parent = game.Workspace.Areas.JudgementHall.IMPORTANT

		game.Workspace.JudgementHall.SilenceMusicGate.Parent = game.ServerStorage

		for i,v in pairs(game.Players:GetPlayers()) do
			if v:IsA("Player") then
				local f = game.ReplicatedStorage.Invites[v.Name.."'s Group"]:GetChildren()
				if f:FindFirstChild("Players") then
					for i,b in pairs(f.Players:GetChildren()) do
						if b:IsA("StringValue") then
							local realplr = game.Players[b.Value]
							local realchar = realplr.Character
							realchar.HumanoidRootPart.CFrame = root.CFrame
						end
					end
				end
			end
		end
	end
end)

Help would be appreciated as I really dont know why it isnt working when the folder exists

instead of findfirstchild try using waitforchild

Remove GetChildren() and swap to WaitForChild(), this should fix it

If I do that then this happens

	for i,v in pairs(game.Players:GetPlayers()) do
		if v:IsA("Player") then
			local f = game.ReplicatedStorage.Invites[v.Name.."'s Group"]:WaitForChild()
			if f:FindFirstChild("Players") then
				for i,b in pairs(f.Players:GetChildren()) do
					if b:IsA("StringValue") then
						local realplr = game.Players[b.Value]
						local realchar = realplr.Character
						realchar.HumanoidRootPart.CFrame = root.CFrame
					end
				end
			end
		end
	end
end

end)

Edit: grammar

It might be because the variable f is equal to the result of :GetChildren(), which is an array of objects. If you remove :GetChildren(), that might solve the issue, since :FindFirstChild() is a function of objects, not arrays. The index, FindFirstChild does not exist for the array returned, so that’s why it errors with “attempt to call a nil value”. I’ll include the updated script below, taken from the original script.

local Players = game:GetService("Players")
script.Parent.ClickDetector.MouseClick:Connect(function(player)
	local folders = game.ReplicatedStorage.Invites
	local root = player.Character:FindFirstChild("HumanoidRootPart")
	local Workspace = game:GetService("Workspace")
	if root then
		
		game.ReplicatedStorage.JudgementHall.Parent = workspace
		
		root.CFrame = CFrame.new(-2808.753, 1550.77, -3419.949)

		script.Parent.Parent.Parent["J-FIGHT"].Parent = game.ServerStorage

		game.ServerStorage["J-NOFIGHT"].Parent = game.Workspace.Areas.JudgementHall.IMPORTANT

		game.Workspace.JudgementHall.SilenceMusicGate.Parent = game.ServerStorage

		for i,v in pairs(game.Players:GetPlayers()) do
			if v:IsA("Player") then
				local f = game.ReplicatedStorage.Invites[v.Name.."'s Group"]
				if f:FindFirstChild("Players") then
					for i,b in pairs(f.Players:GetChildren()) do
						if b:IsA("StringValue") then
							local realplr = game.Players[b.Value]
							local realchar = realplr.Character
							realchar.HumanoidRootPart.CFrame = root.CFrame
						end
					end
				end
			end
		end
	end
end)

This works but the only problem is that it teleports people from different groups / parties too so thats a problem and it produces no error so yeah

nvm it just scans through all groups and not your specific group if theres a fix for that?


this person didnt click it yet they still got scanned through