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

Running Functions about Players?

Asked by
Tor6 0
10 years ago

I have created a game where it chooses a seeker and the rest of the people have to hide in a map(s). I have it basically scripted, except how the game loop is runned by/off. I HAD it runned like this...

game.Players.PlayerAdded:connect(function()
-- code to run the game (which includes teleporting, map choosing, round time, round end gui, more guis, and the loop end --
end)

The problem with this is that the loop runs everytime someone joins the game. So I had this loop run off another piece of code that allowed it so that the game needed 2 players to start. But even still that didn't change anything. The loop can still run multiple times at the same time, messing the game up:( I dont know how to run the loop another way? Plz help?

1 answer

Log in to vote
0
Answered by
SanityMan 239 Moderation Voter
10 years ago

One thing you could do is use a while loop and check the number of players:

local lobbytime = yourintermissionlength
local play = false

while true do
    if game.Players.NumPlayers >= 2 then
        if play == false then
            wait(lobbytime)
            play = true
        else
            --your code
            play = false
        end
    end
end

The way I would prefer would be something like this

repeat wait() until game.Players.NumPlayers >= 2

function game()
    game.Players.PlayerRemoving:connect(function(plr)
        if plr == your_it_or_something or game.Players.NumPlayers < 2 then
            return nil --(or something else you want to put to stop the function)
        end
    end)
    --game code
end

game()

your_it_or_something is what I put for a conditional statement checking if the player was the seeker. Depending on how you track the seeker, you can change this statement. If you can tell me how you keep track of who is "it" then I can help you replace that bit. Here are some basic things:

-if the seeker's NAME is stored in a local variable, change the line to

if plr.Name == seekervariable then --seekervariable would be your local seeker tracking variable

-if the seeker's PLAYER is stored in a local variable, change the line to

if plr == seekervariable then --seekervariable would be your local seeker tracking variable

Once again, it would help if I could know how you store it.

0
k thx! Tor6 0 — 10y
0
what do i do with the your_it_or_something ? Tor6 0 — 10y
0
How are you classifying your "seeker" player? Do you have a variable? I will update my post to give some clarification. SanityMan 239 — 10y
0
Alright I have a gui at the top of the screen that tells you who the seeker is, I had it based of that. Tor6 0 — 10y
0
I also have a timer that ends each game round. Does that effect this coding at all, seeing as the player removal does end this function? Tor6 0 — 10y
Ad

Answer this question