Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Join/Chat Log Webhook ModuleScript not working?

I'm getting an error that I cannot diagnose for some reason. I'm trying to use HTTPService with Discord to send a message to a server, and I'm trying to convert it into a require(). But this error keeps on popping up!

On server: Model.MainModule:3: invalid argument #4 (string expected, got table) Stack Begin Script 'Model.MainModule', Line 3 - function Start Script 'ServerScriptService.Webhook', Line 4 Stack End

Here are the scripts:

(the Require script, in ServerScriptService)

local joinwebhook = "(censored)"
local clogwebhook = "(censored)"

require(CensoredMainModule):Start(joinwebhook, clogwebhook)

(the ModuleScript)

local module = {}
function module.Start(joinhook, cloghook)
	script.WebhookConfig.JoinsHook.Value = joinhook
	script.WebhookConfig.ChatLogHook.Value = cloghook
	script.WebhookConfig.Parent = game.ServerScriptService
	script["Chat Logs"].Parent = game.ServerScriptService
	script.Joins.Parent = game.ServerScriptService
end
return module

(the Joins Script in the ModuleScript)

local webhook = script.Parent.WebhookConfig.JoinsHook.Value
local HTTPService = game.HttpService
local PlaceInfo = game:GetService("MarketplaceService"):GetProductInfo(game.PlaceId)

game.Players.PlayerAdded:Connect(function(plr)
	local stuff = HTTPService:JSONEncode({
		content = plr.Name .. " joined " .. PlaceInfo.Name,
		username = plr.Name .. " - " .. plr.UserId
	})
	HTTPService:PostAsync(webhook, stuff)
end)

(the Chat Logs Script in the ModuleScript)

local webhook = script.Parent.WebhookConfig.ChatLogHook.Value
local HTTPService = game.HttpService
local PlaceInfo = game:GetService("MarketplaceService"):GetProductInfo(game.PlaceId)

game.Players.PlayerAdded:Connect(function(plr)
	plr.Chatted:Connect(function(message, recipient)
		local stuff = HTTPService:JSONEncode({
			content = message,
			username = plr.Name .. " at place " .. PlaceInfo.Name
		})
		HTTPService:PostAsync(webhook, stuff)
	end)
end)

Here is the WebhookConfig folder: MainModule ->WebhookConfig --->ChatLogHook (stringvalue) --->JoinHook (stringvalue)

1 answer

✓ Accepted answer

You called the function with a colon while you defined it with a period.

require(CensoredMainModule):Start(joinwebhook, clogwebhook) -- calling the function with a colon
function module.Start(joinhook, cloghook) -- defining the function with a period

A simple fix to this would be changing the colon to a period.

require(CensoredMainModule).Start(joinwebhook, clogwebhook)

Also do not use Discord as a logging service as you will hit rate limits quickly. As well, you are not filtering the players' messages whatsoever which is against the Roblox Terms of service so I would recommend removing the chat logs or implementing filtering.

This discussion is preserved as it was. New answers, comments, and votes are closed.