How do i fix this script in a local script

So I’ve made this script and it’s not working please help me!! :smile:
here is the script

local gui = script.Parent
local MAINFRAME1 = gui.Parent
local MainFrame = MAINFRAME1.Parent
local Reset = gui.ResetBtn
local Replicated = game.ReplicatedStorage
local Value = game.Workspace.Value
local Chapter1 = game.Workspace:FindFirstChild(“Chapter1”)
local Chapter2 = game.Workspace:FindFirstChild(“Chapter2”)
local Chapter3 = game.Workspace:FindFirstChild(“Chapter3”)
local Chapter4 = game.Workspace:FindFirstChild(“Chapter4”)
local Chapter5 = game.Workspace:FindFirstChild(“Chapter5”)

Reset.MouseButton1Click:Connect(function()
if Chapter1.Parent == workspace then
game.Workspace.Chapter1.Parent = Replicated.Chapters
MAINFRAME1.Visible = false
MainFrame.PlayFrame.Visible = true

		elseif Chapter2.Parent == workspace then
	game.Workspace.Chapter1.Parent = Replicated.Chapters
	MAINFRAME1.Visible = false
	MainFrame.PlayFrame.Visible = true
	
		elseif Chapter3.Parent == workspace then
	game.Workspace.Chapter1.Parent = Replicated.Chapters
	MAINFRAME1.Visible = false
	MainFrame.PlayFrame.Visible = true

		elseif Chapter4.Parent == workspace then
	game.Workspace.Chapter1.Parent = Replicated.Chapters
	MAINFRAME1.Visible = false
	MainFrame.PlayFrame.Visible = true

		elseif Chapter5.Parent == workspace then
	game.Workspace.Chapter1.Parent = Replicated.Chapters
	MAINFRAME1.Visible = false
		MainFrame.PlayFrame.Visible = true
end

end)

here is the error

basically, the chapters aren’t in workspace they are in replicated storage

1 Like

replace

if Chapter1.Parent == workspace then

with

if Chapter1 then

because you’re using :FindFirstChild() in workspace and if it isn’t in workspace it will return nil, otherwise the condition will return true

1 Like

well it kinda worked but also didn’t
when I click the button it doesn’t bring up the GUI and doesn’t put
the chapter to replicated storage

Then it isn’t in workspace in the first place

1 Like

Nvm, use :WaitForChild(instance) instead of FindFirstChild. FindFirstChild is used to check the hierarchy of object

1 Like

wait lemme show you
ill make a video

Ill try that just gemme a second

here is the video

nope WaitForChild doesn’t work i don’t know why…

It doesn’t work because it checks for the chapter once. Place all the local Chapter1 = etc, under Reset.MouseButton1Click

1 Like

Aha, with the video, the hierarchy clearly shows that chapter is a child of game.ReplicatedStorage.Chapters. Not game.Workspace

But I moved the chapter to game.workspace

image
here see i moved chapter1 to workspace

With a script btw if Your wondering!

here look at this
image

I get this error when i use WaitForChild
image

Are you sure the chapters are located in workspace, that’s normally the problem with Infinite yield(s)

1 Like

Try putting all chapters in workspace

1 Like

umm ok sure
i will do that. :wink:

You know what imma use teleport service, that to rest lol