How do I get the local user's ID in a plugin?

  1. What do you want to achieve? Keep it simple and clear!
    I’m working on an antivirus plugin (don’t inquire, will make free) and I’d like to be able to get the local user’s ID.

  2. What is the issue? Include screenshots / videos if possible!
    I can’t very well use game.CreatorId as in a new place, it would return the Templates user. It would also break in Team Create sessions if you don’t own the place.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I haven’t seen any ways to do this on the Developer Hub.

I would like to utilize an API to get the user’s plugin inventory, but I would need the user’s ID.

1 Like

Plugins are client-sided, so you can simply just get the UserId of the LocalPlayer.

game.Players.LocalPlayer.UserId

Although you use server scripts in plugins, they act as local scripts.

1 Like

StudioService:GetUserId is the proper way to get a UserId for plugin purposes. It will return the UserId of the authenticated user for the Studio session.

LocalPlayer is nil in edit mode so you can’t get a UserId from the LocalPlayer. In the case of running a local simulation, the LocalPlayer is not guaranteed to carry the UserId of the authenticated user (an example being local servers which use negative UserIds).
(cc @Volieb)

Output reference for why LocalPlayer shouldn’t be used (local server):

image

12 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.