How can I put 2 "GetDescendants" on the same line?

ah, i’m useless. Although I try to find the solution in various ways, 3 worked in only one GetDescendants, the others. How can I put 2 GetDescendants on the same Line?

local text = script.Parent.MenuKeyPrimero
local ReplicatedStorage = game:GetService("ReplicatedStorage")

game.Players.LocalPlayer.KeysData.InteractiveKey:GetPropertyChangedSignal("Value"):Connect(function()
	game.Players.LocalPlayer.KeysData.InteractiveKey.Value = text.Text
end)

local Interactive = game.Players.LocalPlayer:WaitForChild("KeysData"):WaitForChild("InteractiveKey")

Interactive.Changed:Connect(function(val)
	if #val == 0 then return end
	local key = Enum.KeyCode[val]
	if not key then return end
	for _, item in ipairs(workspace:GetDescendants(), ReplicatedStorage:GetDescendants()) do
		if item:IsA("ProximityPrompt") then
			item.KeyboardKeyCode = key
		end
	end
end)

You can’t, you have to 2 ipairs loops in this case if you want to go through 2 things

local function CheckDescendants(Service)
    for _, item in ipairs(Service:GetDescendants()) do
		if item:IsA("ProximityPrompt") then
			item.KeyboardKeyCode = key
		end
	end
end

Interactive.Changed:Connect(function(val)
	if #val == 0 then return end
	local key = Enum.KeyCode[val]
	if not key then return end
	CheckDescendants(workspace)
	CheckDescendants(ReplicatedStorage)
end)

Edit: Thanks for pointing that out @BullfrogBait, included your reply!

2 Likes

You could make it more readable by creating a function like so:

local function CheckDescendants(Service)
    for _, item in ipairs(Service:GetDescendants()) do
		if item:IsA("ProximityPrompt") then
			item.KeyboardKeyCode = key
		end
	end
end
2 Likes