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

How do you get players in workspace?

Asked by
NotSoNorm 777 Moderation Voter
8 years ago

I have the script to where it puts a boolian in the player but I need to check if the players value is true or not then teleport the player if false. Idk the proper way of doing this. leik?

The only thing that's erroring is :GetChildren()

error: Value is not a valid member of Camera

Spawns = game.Workspace.Spawns
Players = game.Players:GetChildren()
AFKCheck = game.Workspace:GetChildren()

for PlayerTeleport = 1, #Players do
    if game.Workspace:FindFirstChild(Players[PlayerTeleport].Name) then 
        if AFKCheck[PlayerTeleport].Value == false then 
            Players[PlayerTeleport].Character.Torso.CFrame = Spawns[_G.StartingPlaces[math.random(1,#_G.StartingPlaces)]].CFrame * CFrame.new(0,8,0)
            else
        end
    end
end

2 answers

Log in to vote
0
Answered by 8 years ago
game.Players.PlayerAdded:connect(function(plr)

    wait(1)
    player = game.Workspace:FindFirstChild(plr.Name)

end)

Try that out, it will get the players from the Player table and it will find it in Workspace, hope this helps! This isn't the whole question, just the fix by the way.

Ad
Log in to vote
0
Answered by 8 years ago

To get each player in Workspace, do this:

local Players = game.Players:GetPlayers()

for i,Player in ipairs (Players) do
    local Character = Player.Character
end

to count players, use: game.Players.NumPlayers()

0
I've never used ipairs, how would this fit into the script? NotSoNorm 777 — 8y
0
SwaggyDuckie if it isn't a Local Script Player.Character won't work unless you use GetPlayerFromCharacter() UserOnly20Characters 890 — 8y
0
You don't need the parenthesis after NumPlayers since NumPlayers is a property. Spongocardo 1991 — 8y
1
@User, it'd work, you didn't read my script correctly probably. SwaggyDuckie 70 — 8y
View all comments (4 more)
0
I wouldn't really recommend using 'ipair'; When the current Position in a Table hits nil, while using 'ipairs', the loop will stop. :P TheeDeathCaster 2368 — 8y
0
"pairs" might do same. SwaggyDuckie 70 — 8y
0
'pairs' doesn't do the same as 'ipairs'; From my testing with both recently, 'ipairs' (I knew for a long time) stops when the Table position hits nil, then stops the loop, however, 'pairs' appears to skip the 'nil' position of the table, and continues the loop to the next position within the Table, until it reaches the end of the Table. TheeDeathCaster 2368 — 8y
0
Oh, Okay. SwaggyDuckie 70 — 8y

Answer this question