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

Having trouble learning 'and' conditions, help?

Asked by
yurhomi10 192
10 years ago

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

Log in to vote
0
Answered by 10 years ago

"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.

Ad
Log in to vote
0
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
10 years ago

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.

0
alright, lemme try something yurhomi10 192 — 10y
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. User#2 0 — 10y
Log in to vote
0
Answered by 10 years ago

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.

Log in to vote
-1
Answered by 10 years ago

ddd

Answer this question