Need help with CoreGui:WaitForChild

Hello,

I recently created a Stone Positioning Plugin from a kit I made using CFrame, Inspired in Eppobot’s plugin. I am having a serious problems with CoreGui:WaitForChild("Plugin_Gui"). It seems to me that there is some delay for the GUI to appear on CoreGui, but :WaitForChild() should take care of it, I believe. Edit: The plugin keeps working, I just wanted to know how to remove this annoying error.

The problem.

image
I tried to solve this by adding a wait time for CoreGui:WaitForChild("Plugin_Gui", x), and sometimes it worked and sometimes it didn’t.

The script.
--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_      START      _--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_

local plugin = PluginManager():CreatePlugin()
local ChangeHistoryService = game:GetService("ChangeHistoryService")
local gui = script.Parent.RockPlacerGui
local active = false
local version = '1.0'

--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_ 

-- Check if user has loaded plugin before
local hasLoaded = plugin:GetSetting("pluginHasLoaded")
if not hasLoaded then
	plugin:SetSetting("pluginHasLoaded", true)
end

--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_ 

-- Setup Toolbar
local toolbar = plugin:CreateToolbar("Streeteenk")

--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_
 
-- Setup button
local button = toolbar:CreateButton(
	"Rock Placer",
	"",
	"rbxassetid://3458763977"
)
button.Click:connect(function()
	active = not active
	
	if active then
		gui.Parent = game:GetService("CoreGui")
		plugin:Activate(true)
		button:SetActive(true)
		else
		gui.Parent = script.Parent
		button:SetActive(false)
	end
end)

	
--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_

-- Flat and Smooth button functions
local rocktype = true
repeat wait() until game.CoreGui:WaitForChild("RockPlacerGui")

game.CoreGui:WaitForChild("RockPlacerGui").Frame.Flat.MouseButton1Click:Connect(function()
	game.CoreGui.RockPlacerGui.Frame.Flat.Text = "X"
	game.CoreGui.RockPlacerGui.Frame.Smooth.Text = ""
	rocktype = true
end)
game.CoreGui:WaitForChild("RockPlacerGui").Frame.Smooth.MouseButton1Click:Connect(function()
	game.CoreGui.RockPlacerGui.Frame.Flat.Text = ""
	game.CoreGui.RockPlacerGui.Frame.Smooth.Text = "X"
	rocktype = false
end)

--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_

-- Binds function to left click

local mouse = plugin:GetMouse() -- Mouse detection


mouse.Button1Down:connect(function()
local fold = game.Workspace:FindFirstChild("PluginRocks") or Instance.new('Folder',game.Workspace)
fold.Name = "PluginRocks" 
if rocktype == true then	
	
		local flattb = script.FlatRocks:GetChildren()
		local r = flattb[math.random(1,#flattb)]:Clone()
		r.Parent = fold
		local sz = math.random(game.CoreGui.RockPlacerGui.Frame.MinSize.Text, game.CoreGui.RockPlacerGui.Frame.MaxSize.Text)
		r.Rock.Size = Vector3.new(sz,sz,sz)
		r:SetPrimaryPartCFrame(mouse.Hit * CFrame.new( 0, game.CoreGui.RockPlacerGui.Frame.RockPos.Text, 0) * CFrame.Angles(math.random(), math.random(), math.random() ))
	    ChangeHistoryService:SetWaypoint("Rock Added")
	
	end
if rocktype == false then 
	
		local smoothtb = script.SmoothRocks:GetChildren()
		local r = smoothtb[math.random(1,#smoothtb)]:Clone()
		r.Parent = fold
		local sz = math.random(game.CoreGui.RockPlacerGui.Frame.MinSize.Text, game.CoreGui.RockPlacerGui.Frame.MaxSize.Text)
		r.Rock.Size = Vector3.new(sz,sz,sz)
		r:SetPrimaryPartCFrame(mouse.Hit * CFrame.new( 0, game.CoreGui.RockPlacerGui.Frame.RockPos.Text, 0) * CFrame.Angles(math.random(), math.random(), math.random() ))
        ChangeHistoryService:SetWaypoint("Rock Added")

end
end)

--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_ 

game.CoreGui:WaitForChild("RockPlacerGui",45).Credits.Version.Text = "Current Version: " .. version

--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_      END      _--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_

Insert in your command bar: “game:GetService("InsertService"):LoadAsset(3458787882,true).Parent = game.Workspace” or Install.

Thank you for reading.

This isn’t an error, it’s just a warning. All it’s saying is that, based on the fact the RockPlacerGui hasn’t shown up after 5 seconds, it could yield forever.

If you want to stop this happening, you can use an absurdly long timeout argument for your :WaitForChild. If the second argument is a number at all, it won’t give this warning. For example: CoreGui:WaitForChild("Plugin_Gui", math.huge)

2 Likes

I already tried it, I said it before in the post.

1 Like

I recommend using the FindFirstChild then use the WaitForChild. In the game, what happens is that the game critically thinks that you are waiting on a child to be added, followed by the child’s name. I don’t really recommend using WaitForChild for getting the child unless the child is not being inputted into the object and you need to have to get it when it’s added, it’s what we use for WaitForChild

local var = Object:FindFirstChild("Instance_Name") or Object:WaitForChild("Instance_Name")

WaitForChild implements FindFirstChild internally, making this redundant and unnecessary.

2 Likes