I made a script to wait until there are two people in the server. None of the commands under this if statement are working. Can anyone please point out the problem. Just so you know, this is in a ServerScript in ServerScriptService. Thank you for helping.
01 | local plrs = game.Players:GetPlayers() |
02 | local ws = workspace |
03 | local gui = game.StarterGui |
04 |
05 | if #plrs = = 1 then --I changed it to 1 so I could test it alone. |
06 | print "started" |
07 | ws.RedCage:Destroy() |
08 | ws.BlueCage:Destroy() |
09 | gui.ScreenGui.Frame.PreGame.Visible = false |
10 | gui.ScreenGui.Frame.Timer.Visible = true |
11 | gui.ScreenGui.Frame.BluePlayer.Visible = true |
12 | gui.ScreenGui.Frame.RedPlayer.Visible = true |
13 | end |
Thank you for your time.
The GUI
should be player's gui, and it is parented to the player.
And your code should be inside the local script
. As far as that your code is only inside this script, it would be complicated to fix your code.
01 | --This should be the normal script, put it inside Server Script Service |
02 | local plrs = game.Players:GetPlayers() |
03 | local Event = Instance.new( "RemoteEvent" ,workspace) |
04 | Event.Name = "GuiEvent" |
05 | --[[IF YOU WANT TO DELETE THE CAGES GLOBALLY |
06 | local deleted = false |
07 | --]] |
08 | if #plrs = = 1 then --I changed it to 1 so I could test it alone. |
09 | print "started" |
10 | --If you want to test it to yourself, then I will only use one individual inside this statement. |
11 | local PlrGui = plrs [ 1 ] :WaitForChild( "PlayerGui" ) |
12 | Event:FireClient(plrs [ 1 ] ) --Fire the event |
13 | --[[IF YOU WANT TO DELETE THE CAGES GLOBALLY |
14 | if deleted == false then |
15 | ws.RedCage:Destroy() |
Further details: Client-Server Model, Remote Functions and Events
Edit 2020/4/24 20:36 GMT+8 : Fixed typo of the code