:GetChildren() Error?

Can you help me solve this issue?

Here is my Local Script:

--// VARIABLES //--
local Players = game:GetService('Players');
local UserInputService = game:GetService('UserInputService');
local Player = Players.LocalPlayer;
local Character = Player.Character or Player.CharacterAdded:wait();
local PlayerGui = Player:WaitForChild('PlayerGui');
local Game_UI = PlayerGui:WaitForChild('Game_UI');
local Tip_Text = Game_UI.Tip_Text;
local Active = false;
local Object = nil;

--// FUNCTIONS //--
UserInputService.InputBegan:Connect(function(Input)
	if (Active and Input.UserInputType == Enum.UserInputType.Keyboard and Input.KeyCode == Enum.KeyCode.E) then
		Object.Config.Detect_Event:FireServer();
	end;
end);

while wait(.05) do
	Object = nil;
	Active = false;
	Tip_Text.Visible = false;
	for _, Window in pairs(game.Workspace:GetChildren()) do
		local Magnitude = (Character.HumanoidRootPart.Position - Window.Window_Center.Position).magnitude;
		if (Magnitude <= Window.Config.Range.Value) then
			Tip_Text.Text = "Press E to open window";
			Tip_Text.Visible = true;
			Active = true;
			Object = Window;
		end;
	end;
end;

And this is my error message in output:

[16:09:40.155 - Window_Center is not a valid member of Camera](rbxopenscript://www.dummy.com/dummy?scriptGuid=%7BFD548430%2DC4CA%2D4FED%2D8999%2DD8A3522BD3DD%7D&gst=2#24)

16:09:40.156 - Stack Begin

[16:09:40.156 - Script 'Players.honza2555.PlayerScripts.Client_Script', Line 24](rbxopenscript://www.dummy.com/dummy?scriptGuid=%7BFD548430%2DC4CA%2D4FED%2D8999%2DD8A3522BD3DD%7D&gst=2#24)

16:09:40.156 - Stack End

I dont know why… oh

Your script is currently assuming every instance inside Workspace has something called “Window_Center” inside of it, which is not true.

To resolve this issue, wrap the entire inside of your foor loop with this if statement:

if Window:FindFirstChild("Window_Center" ) then "Code here" end

This will make sure there actually is an object called “Window_Center” inside of the current instance before executing any code.

3 Likes

I forgot this… it working now thank you :slight_smile: