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

Trying to make my game consistanly check if theres 2 players, doesn't work. Help?

Asked by 5 years ago

Hi, I'm trying to make my game consistantly check if there is more than two players in the game, and if there is, it disables a gui, and enables some scripts, but this doesn't work. I testing it by joining, and then my friend joined, but the gui didn't go away and the scripts didn't enable. Any Help?

Script:

while true do
    if #game.Players:GetPlayers() >= 2 then
        local SSS = game.ServerScriptService
        local Player = game.Players.LocalPlayer
        local PlayerGui = Player:WaitForChild("PlayerGui")
        PlayerGui:WaitForChild("TwoPlayers").Enabled = false
        PlayerGui:WaitForChild("PartOne").Disabled = false
        SSS:WaitForChild("IntBar").Disabled = false
        game.Workspace:WaitForChild("Script").Disabled = false
        wait()
    end
end
0
try making it print how many players. That might help you see where the issue is.. greenhamster1 180 — 5y
0
I think you shouldn't repeatedly check. All hail the mighty Changed event. xXprohax0r1337Xx 74 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago

If your game is Filtering Enabled then

If your script is a Script then

  You can't access **LocalPlayer** or the stuff in **PlayerGui**.
  

end

If it is a Local Script then

  you can't access the **ServerScriptService**.
  

end

else

Check if there are errors or not.

end

0
So do I gotta use a Remote Event? SBlankthorn 329 — 5y
0
I don't think so. I'll try to explain in an actual answer. lunatic5 409 — 5y
0
Thought maybe people could read an answer in code format on a coding site. climethestair 1663 — 5y
Ad
Log in to vote
0
Answered by
lunatic5 409 Moderation Voter
5 years ago

First of all, are you using a Script or a LocalScript? If you are using a Script, then your problem is that you are trying to use "LocalPlayer" in line 4. You can't access a LocalPlayer with a Script, you must use a LocalScript for that. If you are using a LocalScript, the problem is that in line 3, you are trying to access ServerScriptService. ServerScriptService is not accessible through LocalScript. Try to use another method to access "IntBar", as you are trying to do in line 8. For example, you can place your Script or LocalScript in StarterPlayerScripts, and then access it by finding the player, and then disabling the Script or LocalScript that is in the player. Hope this helps! If it does, please accept my answer.

Answer this question