You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
How to get a Players Username based on a string?
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
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
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)}'`) }
})
]
}
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 })
});
});
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.
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.