Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

2 comments

0

try making it print how many players. That might help you see where the issue is..

0

I think you shouldn't repeatedly check. All hail the mighty Changed event.

2 answers

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

3 comments

0

So do I gotta use a Remote Event?

0

I don't think so. I'll try to explain in an actual answer.

0

Thought maybe people could read an answer in code format on a coding site.

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.