Scripting Book/Chapter 12

From Legacy Roblox Wiki
Jump to navigationJump to search

Introduction

Hello, glad to see you've read this far! Anyhow, in this chapter we are going to learn the methods of the 'Player' instance. I also added something special in this chapter, SYNTAX HIGHLIGHTING!!

IsBestFriendsWith(userId) Method

We're going to learn the 'IsBestFriendsWith(userId)' method. The method type is a boolean and the argument, 'userId' is an int.

The userId argument determines whether or not the given player has the given userId as a best friend.


player = "SoulStealer9875"
Danedude34 = 1836760 --Danedude34's userId
if game.Players:FindFirstChild(player):IsBestFriendsWith(Danedude34) then
     print(player, "has the player with the userId of", Danedude34, "as a best friend!")
end

How does the above example work? Well, the 'player' variable holds the string value of SoulStealer9875, my name. The variable 'Danedude34' contains the int value, '1836760', which is Danedude34's userId. The third line checks if I am in the game and if my best friend's userId is the 'Danedude34' variable, if it is, the text 'SoulStealer9875 has the player with the userId of 1836760 as a best friend!' will be displayed in my output window.

IsFriendsWith(userId) Method

Now we're going to learn about the 'IsFriendsWith(userId)' method. The method type is a boolean and the argument, 'userId' is an int, just like the IsBestFriendsWith() method we learned earlier.


The userId argument determines whether or not the given player has the given userId as a friend.

player = "SoulStealer9875"
Danedude34 = 1836760 --Danedude34's userId
if game.Players:FindFirstChild(player):IsFriendsWith(Danedude34) then
     print(player, "has the player with the userId of", Danedude34, "as a friend!")
end

The 'player' variable holds the string value of SoulStealer9875, my name. The variable 'Danedude34' contains the int value, '1836760', which is Danedude34's userId. The third line checks if I am in the game and if my friend's userId is the 'Danedude34' variable, if it is, the text 'SoulStealer9875 has the player with the userId of 1836760 as a friend!' will be displayed in my output window.

IsInGroup(groupId) Method

This method is just like IsFriendsWith and IsBestFriendsWith, only this one checks if the given player is in the group that consists of the groupId of the argument, 'groupId'.

player = "SoulStealer9875"
groupId = 1337
if game.Players:FindFirstChild(player):IsInGroup(groupId) then
     print(player, "is in the group with the group id of", groupId .. "!")
end

The above example sets the value of the variable 'player' to the string 'SoulStealer9875', sets the value of the value of the int to 1337, checks if 'player' (SoulStealer9875) is in the game and checks if he is in the group with the group id of 'groupId' (1337) and if I am display the text 'SoulStealer9875 is in the group with the group id of 1337!' in my output window.

And we're done!


Go to previous chapter or Continue to Chapter 13