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

Having trouble learning 'and' conditions, help?

nothing is working, only prints 'whats wrong?' in the output...

running = false
enough = game.Players.NumPlayers

if (running == false and enough >= 1) then
	running = true
	while true do
		m = Instance.new("Message", Workspace)
		m.Text = "Now starting a new game!"
		wait(1)
		m:Destroy()
		for i, v in pairs(game.Players:GetChildren()) do
			if v.Character.BoolValue.Value == true then
				print(v.Name .. " has been found")
				v.Character.Torso.CFrame = Vector3.new(10,10,10)
			end
		end
	end
else 
	print("whats wrong?")
	running = false
end

4 answers

✓ Accepted answer

"Most likely the script loads before game.Players.NumPlayers changes to 1 because the server is started and scripts are run before the client is connected to it." - 1Waffle1

game.Players.PlayerAdded:connect(function(plr)
	if (running == false and enough >= game.Players.NumPlayers) then
		--etc.

This will let it check every time a player joins to see if there are enough players.

Most likely the script loads before game.Players.NumPlayers changes to 1 because the server is started and scripts are run before the client is connected to it.

2 comments

0

alright, lemme try something

0

That really doesn't help because you only explained the problem, which you do explain, but it is something pretty confusing to think of the first time. If you could, I would suggest also posting a solution.

Yeah, the script loads before NumPlayers is updated with 1 as it's value. Try asking if enough is greater than (not greater than or equal to) 0. However, you should put that into a looped wait with that set as the condition if you want it to wait until there are enough players.

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