Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 5 years ago
Edited 5 years ago

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

Log in to vote
0
Answered by 5 years ago

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

Ad

Answer this question