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

Same visibility script only works for one gui? Script copy and pasted and edited to fit each gui

Asked by 4 years ago

I have a Start Menu that can take the player either to the Character Select or the Shop, and then back from those. The script works fine for one of them, but not for the other two.

This script functions perfectly for the Character Select:

local CSMenu = game.Players.LocalPlayer.PlayerGui:FindFirstChild("CharacterSelect")
local CSelect = CSMenu.Mainframe
local Startmenu = game.Players.LocalPlayer.PlayerGui:FindFirstChild("StartMenu")
local Startmenuvis = Startmenu.Frame

local function toggleCSelectVisbility()
    CSelect.Visible = true
end

local function toggleMenuVisbility()
    Startmenuvis.Visible = false
end


script.parent.MouseButton1Click:Connect(toggleCSelectVisbility)
script.parent.MouseButton1Click:Connect(toggleMenuVisbility)

However, when reversed like this:

local CSMenu = game.Players.LocalPlayer.PlayerGui:FindFirstChild("CharacterSelect")
local CSelect = CSMenu.Mainframe
local Startmenu = game.Players.LocalPlayer.PlayerGui:FindFirstChild("StartMenu")
local Startmenuvis = Startmenu.Frame

local function toggleCSelectVisbility()
    CSelect.Visible = false
end

local function toggleMenuVisbility()
    Startmenuvis.Visible = true
end


script.parent.MouseButton1Click:Connect(toggleCSelectVisbility)
script.parent.MouseButton1Click:Connect(toggleMenuVisbility)

-then it will not work (back button does not take you back to the menu)

Furthermore, the same script tailored for the Shop menu does not work:

local ShopMenu = game.Players.LocalPlayer.PlayerGui:FindFirstChild("ShopMenu")
local Shop = ShopMenu.MainFrame
local StartMenu = game.Players.LocalPlayer.PlayerGui:FindFirstChild("StartMenu")
local SM = StartMenu.Frame

local function toggleShopVisbility()
    Shop.Visible = true
end

local function toggleSMVisbility()
    SM.Visible = false
end

script.parent.MouseButton1Click:Connect(toggleShopVisbility)
script.parent.MouseButton1Click:Connect(toggleSMVisbility)

This one comes with the output " 16:14:31.622 - Players.DragonessAnimations.PlayerGui.StartMenu.Frame.Shop.Shop:2: attempt to index nil with 'MainFrame'", so I think its trying to search for the Shop Gui within the Start Menu Gui, but I don't understand why as it didn't do that for the Character Select script that works perfectly fine.

In short, the first script works perfectly, while the other two don't.

Thanks for any help.

0
First thing, make only one function and put ur code in that only. Also, at the end, make sure its 'script.Parent' with capital 'P' BestCreativeBoy 1395 — 4y

Answer this question