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.
local plrs = game.Players:GetPlayers() local ws = workspace local gui = game.StarterGui if #plrs == 1 then --I changed it to 1 so I could test it alone. print"started" ws.RedCage:Destroy() ws.BlueCage:Destroy() gui.ScreenGui.Frame.PreGame.Visible = false gui.ScreenGui.Frame.Timer.Visible = true gui.ScreenGui.Frame.BluePlayer.Visible = true gui.ScreenGui.Frame.RedPlayer.Visible = true 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.
--This should be the normal script, put it inside Server Script Service local plrs = game.Players:GetPlayers() local Event = Instance.new("RemoteEvent",workspace) Event.Name = "GuiEvent" --[[IF YOU WANT TO DELETE THE CAGES GLOBALLY local deleted = false --]] if #plrs == 1 then --I changed it to 1 so I could test it alone. print"started" --If you want to test it to yourself, then I will only use one individual inside this statement. local PlrGui = plrs[1]:WaitForChild("PlayerGui") Event:FireClient(plrs[1])--Fire the event --[[IF YOU WANT TO DELETE THE CAGES GLOBALLY if deleted == false then ws.RedCage:Destroy() ws.BlueCage:Destroy() deleted = true end--]] end --=================== --Local Script local Event = game.Workspace:WaitForChild("GuiEvent") local gui = game.Players.LocalPlayer:WaitForChild("PlayerGui") --[[IF YOU WANT TO DELETE THE CAGES ON THE CLIENT SIDE local deleted = false --]] Event.OnClientEvent:Connect(function() gui.ScreenGui.Frame.PreGame.Visible = false gui.ScreenGui.Frame.Timer.Visible = true gui.ScreenGui.Frame.BluePlayer.Visible = true gui.ScreenGui.Frame.RedPlayer.Visible = true --[[IF YOU WANT TO DELETE THE CAGES ON THE CLIENT SIDE if deleted == false then ws.RedCage:Destroy() ws.BlueCage:Destroy() deleted = true end--]] end)
Further details: Client-Server Model, Remote Functions and Events
Edit 2020/4/24 20:36 GMT+8 : Fixed typo of the code