Why does my game think this is a folder when it's not?

I’m getting an error that says this:

AvatarEditorGui is not a valid member of Folder "ReplicatedStorage.AvatarEditor"

This is the specific line of code that apparently has the error:

local doneButton = game.ReplicatedStorage:WaitForChild("AvatarEditor").AvatarEditorGui.Frame.Editor.Done

And this is the entire script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local StarterGui = game:GetService("StarterGui")
local Run = game:GetService("RunService")
local Lighting = game:GetService("Lighting")
local UserInput = game:GetService("UserInputService")

local AvatarPart = game.Workspace:WaitForChild("AvatarGUI")
local AvatarEditor = ReplicatedStorage.AvatarEditor
local AE = require(AvatarEditor.AvatarEditorClient)
local Icon = require(script.Icon)
local Distort = require(script.Distort)

local player = Players.LocalPlayer

local playerModule = require(player:WaitForChild("PlayerScripts"):WaitForChild("PlayerModule"))
local controlModule = playerModule:GetControls()

local defaultMinZoom = player.CameraMinZoomDistance

local sunrays = Lighting:FindFirstChildWhichIsA("SunRaysEffect")
local defaultSunrays = sunrays and sunrays.Enabled or false

local avatarIcon = Icon.new()
:setName("AvatarEditor")
:setImage("rbxasset://textures/ui/ImageSet/LuaApp/img_set_2x_3.png")
:set("iconRectOffset", Vector2.new(158, 375))
:set("iconRectSize", Vector2.new(48, 53))
:setCaption("Avatar Editor")


AE.Started:Connect(function()
	controlModule:Disable()
	UserInput.ModalEnabled = true
	StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, false)
	Distort.Start()
	player.CameraMinZoomDistance = 5
	
	if sunrays then
		sunrays.Enabled = false
	end
end)

AE.Loaded:Connect(function()
	
end)

AE.PermissionFailed:Connect(function()
	
end)


AE.Destroyed:Connect(function()
	
	Distort.Stop()
	StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, true)
	controlModule:Enable()
	UserInput.ModalEnabled = false
	player.CameraMinZoomDistance = defaultMinZoom
	
	if sunrays then
		sunrays.Enabled = defaultSunrays
		end
end)

Run:BindToRenderStep("AvatarEditor", Enum.RenderPriority.Camera.Value, function(delta)
	local alpha = AE:GetAlpha()
	Distort.Position = UDim2.new(-0.3 * alpha, 0, 0, 0)
	Distort.Size = UDim2.new(0.9, 0, 0.9, 0)
	AE:OnRenderStep(delta)
end)

--added
local doneButton = game.ReplicatedStorage:WaitForChild("AvatarEditor").AvatarEditorGui.Frame.Editor.Done

local Debounce = false

AvatarPart.Touched:Connect(function(Hit)
	if not Debounce then
		Debounce = true
		AE:Load()
	else
		if doneButton.Activated then 
			AE:Destroy()
			wait(1)
		Debounce = false
		end
		end
end)

What’s going on?
I’m trying to have the GUI pop-up when the player walks onto an part in the workspace and then close the GUI when the player presses the button.

Give us a screenshot of your Explorer window with the ReplicatedStorage and all folders opened up inside it.

Screen Shot 2022-07-29 at 1.23.21 PM



Screen Shot 2022-07-29 at 2.14.15 PM

The GUI probably just didn’t load in time. Try using another WaitForChild():

local doneButton = game.ReplicatedStorage:WaitForChild("AvatarEditor"):WaitForChild("AvatarEditorGui").Frame.Editor.Done

You have this line local AvatarEditor = ReplicatedStorage.AvatarEditor at the beginning of your script. You should probably put a WaitForChild there.

Best practice when scripting is to not name your variables exactly what the item is.
A lot of people use the practice of taking the first capital letter off, so
local AvatarEditor = ReplicatedStorage.AvatarEditor
would be
local avatarEditor = ReplicatedStorage.AvatarEditor
It makes it easier to differentiate between them, and also keeps the script from confusing the variable and the actual item.

1 Like