What can I do to change my Instance:WaitForChild() script?

I want to make a script that opens an admin gui for me.

Though, I only want it to make a Instance:WaitForChild() if it is me…

The issue is that it will initaite the Instance:WaitForChild() and then shortly after, it will say “Infinite yield on (“MasterGui”)” (Because the player isn’t me and it was trying to wait for the MasterGui to exist even though they couldn’t).

Here is an example of this issue:
An Example of This Issue

Here is the script that I’m currently using… (Note that the 2 scripts are from different scripts corresponds to different objects)

First Script (this one is in the PlayerScripts Folder)

The part that is underlined gives me the infinite yield possible.

script.Parent.Parent.PlayerGui:WaitForChild("MasterGui")
script.Parent.Parent:WaitForChild("PlayerGui")
̲𝗌̲𝖼̲𝗋̲𝗂̲𝗉̲𝗍̲.̲𝖯̲𝖺̲𝗋̲𝖾̲𝗇̲𝗍̲.̲𝖯̲𝖺̲𝗋̲𝖾̲𝗇̲𝗍̲.̲𝖯̲𝗅̲𝖺̲𝗒̲𝖾̲𝗋̲𝖦̲𝗎̲𝗂̲:̲𝖶̲𝖺̲𝗂̲𝗍̲𝖥̲𝗈̲𝗋̲𝖢̲𝗁̲𝗂̲𝗅̲𝖽̲(̲"̲𝖬̲𝖺̲𝗌̲𝗍̲𝖾̲𝗋̲𝖦̲𝗎̲𝗂̲"̲)̲

while true do
	local Dex = script.Parent.Parent.PlayerGui.MasterGui
	if Dex.ResetOnSpawn == true then
		Dex.ResetOnSpawn = false
		script.Disabled = true
		break
	end
end

This second one is found in the PlayerGui
Again, the part that is underlined gives me the infinite yeild:

script.Parent:WaitForChild("MasterGui")
s​̲c​̲r​̲i​̲p​̲t​̲.​̲P​̲a​̲r​̲e​̲n​̲t​̲:​̲W​̲a​̲i​̲t​̲F​̲o​̲r​̲C​̲h​̲i​̲l​̲d​̲(​̲"​̲M​̲a​̲s​̲t​̲e​̲r​̲G​̲u​̲i​̲"​̲)​̲
local SoundGui = script.Parent.SoundGui
local SilentButton = SoundGui.OpenMusicSilent
local PauseButton = SoundGui.OpenMusicStop
while true do
	if script.Parent.MasterGui.SideMenu.Position == UDim2.new(1, -330, 0, 0) then
		SilentButton:TweenPosition(UDim2.new(0.426, 1, 0.845, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Quart, 1, false)
		PauseButton:TweenPosition(UDim2.new(0.426, 1, 0.93, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Quart, 1, false)
	elseif script.Parent.MasterGui.SideMenu.Position == UDim2.new(1, 0, 0, 0) then
		SilentButton:TweenPosition(UDim2.new(0.776, 1,0.845, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Quart, 1, false)
		PauseButton:TweenPosition(UDim2.new(0.776, 1,0.93, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Quart, 1, false)
	end
end

Wrap everything up in

if game.Players.LocalPlayer.UserId == YOURUSERID then
end

That should do.

2 Likes

Thank you! I will try that! :smiley: