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

Why are none of the commands under this if statement not running?

Asked by
DesertusX 435 Moderation Voter
5 years ago

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.

01local plrs = game.Players:GetPlayers()
02local ws = workspace
03local gui = game.StarterGui
04 
05if #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
13end

Thank you for your time.

0
PlayerGui, not StarterGui. Ziffixture 6913 — 5y
0
Thank you :) I will try DesertusX 435 — 5y
0
Strange, still doesnt do anything DesertusX 435 — 5y
0
PlayerGui is parent-ed in Player. In the case there is only one Player, we can do like this to get the PlayerGui: local gui = plrs[1].PlayerGui Block_manvn 395 — 5y
View all comments (2 more)
0
How could i do that if there are 2 players? DesertusX 435 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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
02local plrs = game.Players:GetPlayers()
03local Event = Instance.new("RemoteEvent",workspace)
04Event.Name = "GuiEvent"
05--[[IF YOU WANT TO DELETE THE CAGES GLOBALLY
06local deleted = false
07--]]
08if #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()
View all 38 lines...

Further details: Client-Server Model, Remote Functions and Events

Edit 2020/4/24 20:36 GMT+8 : Fixed typo of the code

0
I'm getting an error in the output which says "OnServerEvent can only be used in the server" from the LocalScript. DesertusX 435 — 5y
0
I fixed it now. LinavolicaDev 570 — 5y
0
thx DesertusX 435 — 5y
Ad

Answer this question