Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Got problem, cant access another GUI from a script, can someone help?

So uh i got a problem, roblox keeps telling me that there is error in line.

local plr = game.Players.LocalPlayer
local object = script.Parent.Parent
-- local Menu = plr.PlayerGui.btn == error
local button = script.Parent
local toggle = false

object.AnchorPoint = Vector2.new(0.5, 0.5)
object.Position = UDim2.new(0.5, 0, 0.5, 0)
 
local function onButtonActivated()
	if toggle == false then
		object:TweenSize(UDim2.new(0, 0, 0, 0))
		script.Parent:TweenSize(UDim2.new(0, 0, 0, 0))
        Menu:TweenPosition(UDim2.new(0, 0,0.887, 0))
		wait(1)
		object.Visible = false
		script.Parent.Visible = false
		toggle = true
	else		
		wait(1)
		toggle = false
	end
end
 
button.Activated:Connect(onButtonActivated)

so i tried all the ways, script.Parent, but it always was saying "btn is not a valid member of PlayerGui" but if you look there musn't be any problems? screenGUI named btn

1 answer

✓ Accepted answer

The ScreenGui wasn't having time to load. Use local menu = plr.PlayerGui:WaitForChild("btn") to yield until it does load.

This discussion is preserved as it was. New answers, comments, and votes are closed.