Attempt to index nil with 'Name' error with Split string function

Why output saying: attempt to index nil with ‘Name’ (8-th line)

script.Parent.runCommand.Event:Connect(function(cmd:string)
	local split = cmd:split(" ")
	print(split[1] .. "///" .. split[2] .. "///" .. split[3])
	if split[1] == "function" then
		if split[2] == "openapp" then
			local appname = split[3] .. ""
			local gui:ScreenGui = script.Parent.Parent.Parent.Parent:FindFirstChild(appname)
			print(gui.Name)
			gui.Enabled = true
		end
	end
end)

Is it able to get an instance? What happens when you tell it to print appname?

it’s print a correct string


to…

local gui:ScreenGui = script.Parent.Parent.Parent.Parent:WaitForChild(appname)

See if that works because I’ve had the same situation before.

What happens when you try

print(script.Parent.Parent.Parent.Parent:FindFirstChild(appname))

Nothing, you’re trying to print out an Instance, not a String.

Oh it’s my error. Turns out it finding not in playergui, its finding in players.
But i see it due to WaitForChild() output (Infinite yield possible on ‘Players:WaitForChild(“TSUI”)’)

1 Like

Aren’t we trying to find an instance though? If Roblox finds what you want it to find, doesn’t it print the name of the instance?