How to get a Players Username based on a string?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    How to get a Players Username based on a string?
  2. What is the issue? Include screenshots / videos if possible!
    When I put player connected OnServerEvent, the player.Name isn’t really registering as the players user when the Server.HandleJoinRequest fires.
    It’s not getting the players username, it’ll give me an error:
    Error: Required argument “userId” is missing
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

No solutions, even tried looking at other forums.

Then you didn’t fill in the UserID parameter. Just give it player.UserId.

This is the function being called:

function JoinRequests() { // Validator for HandleJoinRequest
	return [
		check('Group')
			.custom((value, { req, loc, path }) => {
				if (typeof req.body.Group === "number") { return value; } else { throw new Error(`Parameter 'Group' must be an integer, not type '${typeof (value)}'`) }
			}),
		check('Username')
			.custom((value, { req, loc, path }) => {
				if (typeof req.body.Username === "string") { return value; } else { throw new Error(`Parameter 'Username' must be a string, not type '${typeof (value)}'`) }
			}),
		check('Accept')
			.custom((value, { req, loc, path }) => {
				if (typeof req.body.Accept === "boolean") { return `${value}` } else { throw new Error(`Parameter 'Accept' must be a boolean, not type '${typeof (value)}'`) }
			})
	]
}

No UserId is indicated or needed.

Show the handleJoinRequest function.

app.post("/HandleJoinRequest", JoinRequests(), Validate, function (req, res, next) {
    // At this point the request has been authenticated and body contents are validated.

    let Group = req.body.Group
    let Username = req.body.Username
    let Accept = req.body.Accept

    roblox.handleJoinRequest({ group: Group, username: Username, accept: Accept })
        .then(() => {
            console.log(`Handled join request of user ${Username} successfully.`)
            res.status(200).send({
                error: null,
                message: `Handled join request of user ${Username} successfully.`
            });
        })
        .catch(err => {
            console.log(err);
            res.status(500).send({ error: err.message })
        });
});
1 Like
let roblox = require("noblox.js");

roblox = noblox.js

Which line is causing the error?

		Server.HandleJoinRequest(groupID, player.Name, Accept)

I assume you forgot to remove the userid parameter from the HandleJoinRequest function inside of the Server module

My guess is that the server/api you’re using to accept the join request is supposed to take a userID, check the function to make sure there isn’t a parameter for the userId.

Nope, I didn’t.

Server.HandleJoinRequest = function(GroupId, PlayerUsername, Boolean)
	assert(typeof(GroupId) == "number", "Error: GroupId must be an integer") -- Throw error if GroupId is not an integer
	assert(typeof(PlayerUsername) == "string", "Error: PlayerUsername must be a string") -- Throw error if PlayerUsername is not a string
	assert(typeof(Boolean) == "boolean", "Error: Boolean must be a boolean value") -- Throw error if Boolean is not a boolean value

	local Body = {
		Group = GroupId;
		Username = PlayerUsername;
		Accept = Boolean; -- true or false
	}
	
	local Success, Result = pcall(function()
	    return Request('HandleJoinRequest', Body)
	end)
	
	print(Result)
end

There’s no parameter for the userId, it’s checking for the players username by a string value, however, I don’t know how to make a string value based on a players username when someone connects to the game.

Is the error returned from the website or is it a roblox error?

ROBLOX Error, I’m using noblox.js features for my vps coding on repl.

Can you show a screenshot of the whole error stack?

Do you have discord by any chance, we can further discuss on discord.

Add: DivideAndConquere#0001

Since the year I joined ROBLOX 2012, started developing from building to LUA, .js, C#, Python, etc as the years progress.

1 Like

WOW!, thanks for being scripting so far and helping people

Please post it here so other people can help you too.