New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
2

How to know when the player is a Guest?

Asked by 5 years ago

Hey, guys. So I've been working on this Gui that shows the player's avatar picture when they join the game by finding their userId. It works great; but that's not the problem.

You see, when I played as a Guest, I noticed that there was no avatar picture - it was just a picture with an X. This means that Guests do not have userIds correct?

I'm not so sure, but I made a TextLabel that had the word"Guest" on it appear whenever the userId of the player couldn't be found; but it's not working...

This is the script inside the TextLabel (It is a localscript):

local button = script.Parent
local userid = script.Parent.Parent.Parent.Parent.Parent.userId -- (The parenting here is correct!)

if userid == nil then
    button.Visible = true
end

I think I'm trying to veer into a completely different direction, but could anyone please explain to me how to accomplish this? THANKS!

1 answer

Log in to vote
3
Answered by 5 years ago

To me, to check if a 'Player' is a Guest, is to check:

  1. If the starting of the Name is Guest

  2. If the Player's userId property is a Negative number

There are multiple ways of checking if the Player is a Guest, but, I have only listed two.

For the code, we will require the following codes:

  1. The if Statement

  2. Let's try using a LocalScript, and using the LocalPlayer to get the Client

  3. Using the sub-string method to check the Name/Characters within the String

Now, with all this in mind, let us write the code;

local button = script.Parent --From the original code; Variable 'button' is identifying the Script's Parent
local plr = game.Players.LocalPlayer --Variable 'plr' is now identifying the 'LocalScript''s Client

if plr.userId <= -1 or plr.Name:sub(1,6) == "Guest " then --The code here is checking if the Player's 'userId' property is less than or equal to '-1', or, if the Player's Name/String Characters between '1-6' is 'Guest ' [Real Guest use Spaces in their names, fake ones don't]
button.Value = true --If the Player is a real 'Guest', then it will set the 'button''s 'Visible' property to true, making the GUI appear/Visible to the Client
end --This ends the chunk to the 'if' statement

Hope this helped!

0
Thanks so much! dpark19285 370 — 5y
0
No problem, glad to help! :D TheeDeathCaster 2309 — 5y
0
I recommend just using the ID, since a player can name themselves "Guest" and not actually be a guest. aquathorn321 816 — 5y
1
That is why I added a space ' ' to the 'Guest' string, every 'Guest' has the name 'Guest ', then the random number, there is a space between the Name and Number [E.xx; 'Guest' '1337'], and, in the code, it is doing just that. @Aquathorn321 TheeDeathCaster 2309 — 5y
Ad

Answer this question