Problem with server firing

  1. What do you want to achieve? Keep it simple and clear!
    I wanna achive my local script fire server when object name is nil(not exist)
  2. What is the issue? Include screenshots / videos if possible!
    I don’t know why, but it says my print which means smth works wrong
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tryed to add a loops , waits and etc, still nothing

Firing script:

local RE = game.workspace.REs.FactoryCloned
local Factory = game.Workspace.Factory
local Factory1 = Factory:GetChildren()
while Factory1.Name == nil do
if Factory1.Name == "Factory1" then
		RE:FireServer()
	end
	wait(0.5)
	end

Main Script:


local DB = true
local MoneyLevel = game.workspace.Factory.MoneyLevel
local SpeedLevel = game.workspace.Factory.SpeedLevel
local Brick = game.Workspace.Factory.Factory1.Brick
local RE = game.Workspace.REs.FactoryCloned
local MainPart = game.Workspace.Factory.Factory1.MainPart
RE.OnServerEvent:Connect(function(player)
	local PlrStats = player.PlayerGui:WaitForChild("PlrStats")
	local FactoryBrokenValue = PlrStats.FactoryBroken
	local Money = player.leaderstats.Money
	local Bricks = player.leaderstats.Bricks
		local BrickClone = Brick:Clone()
		BrickClone.Parent  = game.Workspace.Factory.Factory1.Brick
		BrickClone.Transparency = 0
		BrickClone.Anchored = false
		BrickClone.CanCollide = true
		if BrickClone.Position == Vector3.new(42.434, 10.789, -336.925) then
			print("Brick Position is right!")
			Bricks.Value = Bricks.Value + (1 * MoneyLevel)
			BrickClone:Destroy()
			print("Brick destroyed!")
		end
		wait(SpeedLevel)
	end)
print("Smth Wrong")
while Factory1.Name == nil do
if Factory1.Name == "Factory1" then
		RE:FireServer()
	end
	wait(0.5)
	end

Let’s assume in the first line, Factory1.Name does NOT equal nil. What will happen is that the second line with the if statement will NOT run. Because you’re running the code WHILE it’s nil, if it gets a value, then it will SKIP whats in the while loop entirely. So even if factory has a name, it will NOT reach the if statement, because it will break out of the while loop before ever reaching the if statement.