How i can rewrite this script?

How i can rewrite script?

local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local PlayerGui = LocalPlayer:WaitForChild("PlayerGui")
local list = game.Players.LocalPlayer.PlayerGui.PlayersLists

script.Parent.MouseButton1Click:Connect(function()
    list.Playerlist.Visible = true
	list.Leaderboard.Header.Visible = true
	wait(0.03)
	script.Parent.Parent.PlayButton.Visible = false
	script.Parent.Parent.PlayBackground.Visible = false
	script.Parent.Parent.Parent.ShopFunction.Visible = false
	script.Parent.Parent.Parent.Line.Visible = false
	script.Parent.Parent.Parent.Line2.Visible = false
	script.Parent.Parent.Parent.SubTitle.Visible = false
	script.Parent.Parent.Parent.Title.Visible = false
	script.Parent.Parent.Parent.Title.Back.Visible = false
	script.Parent.Parent.Parent.SubTitle.Back.Visible = false
	script.Disabled = true
end)

this script making error, this can’t found the list (idk why, if PlayerList,PlayerGui has all what we need)
error what sent roblox:

  19:35:03.901  PlayersLists is not a valid member of PlayerGui "Players.SerBogdan03.PlayerGui"  -  Client - PlayScript:4
  1. im refraining from making the average ‘stop making my eyes bleed!!!’ remark when i say this but PLEASE, if you’re gonna reference the same thing multiple times like you are when you continuously write script.Parent.Parent, make a variable for it instead, it will make the code look so much cleaner
  2. it would look even more cleaner if you put all these GUIObjects into one table and then ran through the table with a loop to set all their visibility to false instead of long, seperate lines
  3. your error is probably coming from ‘PlayerLists’ either not existing at all or not loading in yet, try adding a :WaitForChild() for that too

Why not change the list line to be this:

local list = PlayerGui:WaitForChild("PlayerLists")

Infinite yield possible on ‘Players.SerBogdan03.PlayerGui:WaitForChild(“PlayerLists”)’ error :confused:

That means playerlists doesnt exists I though that was a gui you made

EDIT: So what is PlayersLists?

how your code should look if you followed step 2

local GUIObjects = {-- insert all the things you want to make invisible
}
script.Parent.MouseButton1Click:Connect(function()
	list.Playerlist.Visible = true
	list.Leaderboard.Header.Visible = true
	wait(0.03)
	for idx, GUIObject in pairs(GUIObjects) do
		GUIObject.Visible = false
	end	
	script.Disabled = true
end)

yeah like @nontoxicguy1 said maybe you’re referencing it wrong, see if its actually parented to StarterGui

You said you are getting the following error:
Infinite yield possible on ‘Players.SerBogdan03.PlayerGui:WaitForChild(“PlayerLists”)

On the picture you’ve just posted we can see that It’s ‘PlayersLists’ instead of ‘PlayerLists’ so I believe you’re actually referencing it wrong, try to fix that and see if the :WaitForChild actually works

1 Like

huh… are you sure the code freezes at the new WaitForChild line? sometimes it sends that error due to lag but it can still run after

also why have both the replies above me been removed lol

The main task of this script, originally conceived by me, is to hide some game interfaces, and make others visible, in this case, after the player has clicked on the start button of the game, his menu interface will close and a sheet with players will open, which is located on the right side.

ok but that doesnt really answer my questions :skull:

And yes, the script gives exactly this error.

Please take a look at the answer I posted earlier and give us an update!

ignore this i just saw @Isaque232 's message and see why it isnt working now haha

Does not work and it is also unknown why.

Sorry I put the wrong name in you need to change it. Didn’t realize you had another s in there.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.