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

Unable to find player in workspace?

Asked by 4 years ago

I have a script that should get all the players on the team "Playing" and have a 50% of doing an action, but for some reason my server script cannot find the player in the workspace, when I ask it to print the player, it prints "jediplocoon" which is the name of the only player in the game (me), but when I try and find my name in the workspace it turns up as nil. I would appreciate it if you could point me in the right direction, and hopefully explain why this script doesn't work, so I don't make this mistake again. Here's my script:

local plrs = game.Teams.Playing:GetPlayers()
for i = 1, #plrs do
    print(plrs[i])
    local num = math.random(1, 2)
    if num == 1 then
        local player = game.Workspace:FindFirstChild(plrs[i])
        print(player)
    end
end
0
plrs[i].Name as it takes a string User#5423 17 — 4y
0
yeah just add .Name to the prints greatneil80 2647 — 4y
0
thanks! worked like a charm after I added the .Name jediplocoon 877 — 4y
0
You can also go through the player itself plrs[i].Character though you should be checking that the player has a character User#5423 17 — 4y

Answer this question