Error in script

Hey, I was working on a UI script and ran into this error
Frame is not a valid member of ScreenGui "ScreenGui" for the last line of the script

Script
	local ScrUI = Instance.new("ScreenGui")
	local ImgUI = Instance.new("ImageLabel", ScrUI)
	local Frame = Instance.new("Frame", ScrUI)
	
	ImgUI.Size = UDim2.new(1, 0, 1, 0)
	ImgUI.ScaleType = Enum.ScaleType.Crop
	ImgUI.Image = Dictionaries.Images.BackgroundImage
	ImgUI.Name = "Image"
	ScrUI.DisplayOrder = 0
	ScrUI.Name = "MainBackground"
	ScrUI.IgnoreGuiInset = true
	ScrUI.Parent = player.PlayerGui
	
	ScrUI = Instance.new("ScreenGui")
	Frame.BackgroundTransparency = 1
	Frame.Size = UDim2.new(1, 0, 1, 0)
	
	for i = 1, 3, 1 do
		Frame:Clone().Parent = ScrUI
	end
	ScrUI.Frame.Name = "Left"
	ScrUI.Frame.Name = "Right"
	ScrUI.Frame.Name = "UP"
	ScrUI.Frame.Name = "Down"

Line 14, you set the value of “ScrUI” to a brand new ScreenGui instance despite creating it initially at line 1. Delete this line and the error should go away. I also advise manually setting the parent of each item after configuration but as far as I know, that’s personal preference.

1 Like

nvm fixed it

ya just noticed it now