Is your script different from what you sent (module script) because I don’t see you sending the UserId anywhere in the modules function? I’m really not sure how to stop the error other than adding a parameter before boolean
.
local Server = {}
local HttpService = game:GetService("HttpService")
local Configs = require(script.Parent.Configs)
local function Request(Function, RequestBody)
--Before sending the request, add our auth_key to the body
RequestBody["auth_key"] = Configs.AUTH_KEY
local response = HttpService:RequestAsync(
{
-- The website to send the request to. Function is the extended part of the URL for specific functions.
-- In this case, Function = 'GroupShout'
-- Example:
-- "Configs.BaseUrl..Function" would be equal to: http://test-app.glitch.me/GroupShout
Url = Configs.BaseUrl..Function,
-- The request method (all of ours will be POST)
Method = "POST",
-- We are sending JSON data in the body
Headers = {
["Content-Type"] = "application/json"
},
-- The body of the request containing the parameters for the request
Body = HttpService:JSONEncode(RequestBody)
}
)
if response.Success then
print("Status code:", response.StatusCode, response.Body)
print("Response body:\n", response.Body)
return response.Body
else
print("The request failed:", response.StatusCode, response.Body)
return response.Body
end
end
Server.Promote = function(GroupId, UserId)
assert(typeof(GroupId) == "number", "Error: GroupId must be an integer") -- Throw error if GroupId is not an integer
assert(typeof(UserId) == "number", "Error: UserId must be an integer") -- Throw error if UserId is not an integer
local Body = {
Group = GroupId;
Target = UserId;
}
-- pcall the function 'Request', with arguments 'Promote' and Body
local Success, Result = pcall(function()
return Request('Promote', Body)
end)
print(Result)
end
Server.Demote = function(GroupId, UserId)
assert(typeof(GroupId) == "number", "Error: GroupId must be an integer") -- Throw error if GroupId is not an integer
assert(typeof(UserId) == "number", "Error: UserId must be an integer") -- Throw error if UserId is not an integer
local Body = {
Group = GroupId;
Target = UserId;
}
local Success, Result = pcall(function()
return Request('Demote', Body)
end)
print(Result)
end
Server.SetRank = function(GroupId, UserId, RankId)
assert(typeof(GroupId) == "number", "Error: GroupId must be an integer") -- Throw error if GroupId is not an integer
assert(typeof(UserId) == "number", "Error: UserId must be an integer") -- Throw error if UserId is not an integer
assert(typeof(RankId) == "number", "Error: RankId must be an integer") -- Throw error if RankId is not an integer
local Body = {
Group = GroupId;
Target = UserId;
Rank = RankId;
}
local Success, Result = pcall(function()
return Request('SetRank', Body)
end)
print(Result)
end
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
Server.GroupShout = function(GroupId, ShoutMessage)
assert(typeof(GroupId) == "number", "Error: GroupId must be an integer") -- Throw error if GroupId is not an integer
assert(typeof(ShoutMessage) == "string", "Error: ShoutMessage must be a string") -- Throw error if ShoutMessage is not a string
local Body = {
Group = GroupId;
Message = ShoutMessage;
}
local Success, Result = pcall(function()
return Request('GroupShout', Body)
end)
print(Result)
end
return Server
Server Module ^
local HttpService = game:GetService("HttpService")
local Server = require(script.Server)
game.ReplicatedStorage.AcceptJoinRequest.OnServerEvent:Connect(function(player, Boolean)
local groupID = 5251151
local Boolean = game.ReplicatedStorage.AcceptJoinRequest.Accept
if Boolean then
print("yes")
Server.HandleJoinRequest(groupID, player.Name, Boolean)
end
end)
Server Script ^
I removed player.UserId and still get the same error.
Here’s one of the coding in my vps:
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)}'`) }
})
]
}
You’re defining a BoolValue object not the actual value of it. In your module you are using the assert function to make sure that the variable Boolean is an actual bool, but since you are sending an BoolValue object, the condition is not being met and the assert function throws the error that you set it to:
Just make sure your doing .Value
when you define the Boolean variable and send the actual bool as the argument.
And how would I accomplish to getting the value of a boolean, if I keep getting the Boolean as an Object.
You simply do what you did previously but with .Value:
local Boolean = game.ReplicatedStorage.AcceptJoinRequest.Accept.Value
That worked, however, it pops up a new error:
The request failed: 500 Internal server error: Error: Required argument "userId" is missing - Server - Server:40
00:57:27.739 Internal server error: Error: Required argument "userId" is missing - Server - Server:111
Could you screen shot or post line 40 and line 111?
I believe the error is from the website that you are sending the request to (I’m guessing your using glitch or heroku?). Are you sure your body data contains all the required arguments?
You’re storing the players username but are you actually using it? It seems like you’re suppose to send the userId (similar to what all the other functions do).
I can’t really tell what your doing wrong as I would need to see the code handling the request but I’m guessing based off the response, the issue is what I stated above.
maybe try
game.ReplicatedStorage.AcceptJoinRequest.OnServerEvent:Connect(function(player, Accept)
if Accept then
print("yes")
Server.HandleJoinRequest(groupID, player.Name, player.UserId, Accept.Value) -- Line the error is coming from
end
end)
I’m currently in school so I might be incorrect…
I’m using repl for my vps hosting, glitch isn’t reliable anymore.
If I added a Accept “.Value” it’ll add in a nil, as I already defined the Value early in the script:
local Accept = game.ReplicatedStorage.AcceptJoinRequest.Accept.Value