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

How would I get the other players in the game?

Asked by 6 years ago

Hey! I've been wondering how to get the players in my game but make it ignore myself. I'm pretty sure this is a simple couple line script. I've tried GetPlayers(), game.Players:GetChildren(), etc... Nothing really works. I've also tried the "for i,v in pairs()) do" thing.

0
if v ~= player then TheeDeathCaster 2368 — 6y
0
oh, I feel stupid then lol. The_MRAP 4 — 6y
0
Idk why I just constructed that whole answer. KingLoneCat 2642 — 6y
0
local players = game.Players.LocalPlayer ? doilikepancakes 0 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

Hey quack,

What you are trying to do is impossible! Just kidding. Anyways, you just need to make a LocalScript(client-side of course) and loop through all the players and put an if statement in the loop to check if the player that it's currently looping through has the same name as the LocalPlayer's. If it doesn't, then you can go ahead and execute the rest of the code. Easier shown than just explaining so, check the code below and I'll explain line by line, unless it's obvious.


Script Example

local plrs = game:GetService("Players"); -- Players Service.
local plr = plrs.LocalPlayer; 

function check_plrs()
    for _, plr2 in next, plrs:GetPlayers() do -- For each iteration, :GetPlayers() returns a table with all of the players inside of it.
        if plr2.Name ~= plr.Name then -- Checks if the current player it's looping through is the LocalPlayer or not.
            print("It's not me; it'", plr2.Name.."."); 
        end
    end
end

Well, I hope I helped and have a nice day/night.

Thanks,

~~ KingLoneCat

Ad

Answer this question