Can anyone tell me if this would work? i can’t test due to the fact that I nothing have any kind of to sign up with my video game / and this can not be tested utilizing server clients
It need to go with all the football player in the game, if the player no yourself, then it continues to then examine if said player is in her friends list. If the player isn’t her friend, then it will finally print this football player name, and then move on to to the next player.
You are watching: How to know what game someone is playing on roblox
for i, allPlayers in pairs(Players:GetPlayers()) doif allPlayers.Name ~= Player.Name thenfor i, yourFriends in pairs(Players:GetFriendsAsync(Player.UserId)) doif allPlayers.Name ~= yourFriends then print(allPlayers.Name)endendendendProblem with this is, i’m not certain is due to the fact that I have actually 2 because that loops running, if the print would publish multiple times because that the exact same player. It have to only print once and also move on, so then at the end it will have printed all the football player in game who aren’t my friends.
How perform I use GetFriendsAsync()?
I wanna get access to a list of a player"s friends and also the amount they have. Can someone show how to use it?
Take a look at at this if friend haven’t already, i’m pretty certain they administer sufficient details for you to number out just how to attain what you want
Hard to tell because I’m ~ above mobile, however this could get messy really quickly. Have actually you had a look in ~ Player.IsFriendsWith instead? This will you a most trouble.
Your existing operation:Iterate with each player. Check if the iterated player no the very same as the requesting player.Iterate v the player’s girlfriend list. Girlfriend now need to examine if the requester isn’t on the target’s friends list.
This obviously quite inefficient, so making use of IsFriendsWith, friend can cut that under entirely and stay within the limit of the game.
for _, yourPlayer in pairs(Players:GetPlayers()) carry out if no (yourPlayer.Name == myPlayer.Name) and also not (yourPlayer:IsFriendsWith(myPlayer.UserId)) then print(yourPlayer, "is no my friend!") endendThis one cuts under loop and also size by half.Iterate with each player.Check that the iterated player is not the same as the requesting player, climate if they’re friends. If both are false, the other player is not friends with the requesting player.
I personally wouldn’t recommend making use of either the the last two unless you have a use situation that requires friends regardless of presence. That consists of creating a sign up with Friends home window or similar.
Given the nature the the thread in wanting to check players on the present instance and also if they no friends, iterating with each player and using IsFriendsWith is the best course of action here. An easy and efficient, minus any kind of potential caching (I perform not believe it caches though).
The other two would current unnecessary overhead and also a slim reinventing that the wheel for existing techniques of check status in between two users.
Alternatively to this, you might get a list of the Player’s friends as soon as with GetFriendsAsync rather of having to make API calls because that each player.
neighborhood Players = game:GetService("Players") local player = game.Players.Whoever regional playerFriends = Players:GetFriendsAsync(player.UserId) local function findFriend(friends, name) for i,plr in pairs(friends) execute if plr.Username == surname then return i finish end return false finish for _, plr in pairs(Players:GetPlayers()) do if no findFriend(playerFriends, plr.Name) then print("This is no my friend") finish end
not a great idea. Girlfriend can readjust over the course of a session. If friend cache the player’s friends as soon as per session, you become unable come accommodate because that any new friends a player adds.
This also goes earlier to the illustration board of using 2 loops and using a role that isn’t presence-dependent, which gift unnecessary overhead. OP only wants to inspect status in between two players in an instance.
Eezby (Ezby) July 23, 2019, 2:11pm #7
That is true, despite an added friend in the current session can just be added to the cache.
colbert2677 (Adriftingly) July 23, 2019, 2:13pm #8
If you’re willing to refresh the change every so often? Sure. In ~ that allude though, uneven the role call takes enough time to it is in noticeable, girlfriend might also not cache. The brings us back to the code seen in the OP.
See more: What Is Meant By Semiconservative Replication Definition, Semi Conservative Dna Replication 2
There’s much less involvement and tiny to no overhead by performing a direct inspect to player relationships over the iterated players.
I fully agree, it just becomes very inefficient if it is extensively used in which reason it’s probably better to border the API calls. If it’s just a couple of checks every so frequently I think that the OP and your code would be the method to go