Module not working, no errors in the console

Hey devs. I scripted myself a module that could kick anyone I don’t want in my game, but it’s don’t work.

I tried it on me to test, but nope.

Module:

local moderation = {}

local function PlrKick(plr, reason)
	if not plr then
		warn("Module has been paused, waiting for player... | Moderation Module Lite")
		task.wait(plr)
		if plr then
			game:GetService("Players"):FindFirstChild(plr)
			if reason ~= nil then
				plr:Kick(reason)
			else
				plr:Kick("You have been kicked from the game, no reasons where specified.")
			end
		end
	end
end

return moderation

Script calling the function:

local lite = require(game:GetService("ServerScriptService").ModerationModule_Lite)
local plr = game:GetService("Players")

if plr.Name == "achdef" then
	lite:PlrKick("achdef", "idk")
end

Help would be appreciated.

task.wait(plr) ?
plr is not a number
try something else

like repeat wait() until plr ~= nil

wait() isn’t very good at all. task.wait however do not create delays; I’ll see if it’s work.

i know but task.wait() will make it crash (atleast for me) so i use wait() instead

Nope, still not kicking me. And again, there is no errors.

then dont add the wait for plr function, just check for it

if they ddidnt find it then just warn they didnt find the player

Does your console output any errors? They could help you and us figure out the problem.

Edit:My bad.

he said there isnt any errors, have you read the topic yet

No, and @regexman I already got a warn, the warn himself won’t pop up so I guess it’s see I’m in game.

Right now, that is my script:

local moderation = {}

local function PlrKick(plr, reason)
	if not plr then
		warn("Module has been paused, waiting for player... | Moderation Module Lite")
		repeat until plr ~= nil
		if plr then
			game:GetService("Players"):FindFirstChild(plr)
			if reason ~= nil then
				plr:Kick(reason)
			else
				plr:Kick("You have been kicked from the game, no reasons where specified.")
			end
		end
	end
end

return moderation

thats what i exactly said, if you wait for the player it will yield for other scripts too

delete “repeat until plr ~= nil” it will make you crash

dont wait for the player as it yields other scripts too, that may cause being busy if theres so much requestss

I didn’t crash tho, and my roblox studio didn’t crash either.

(changed)

still delete it

“dont wait for the player as it yields other scripts too, that may cause being busy if theres so much requestss”

You’re just returning an empty table?

You aren’t connecting the function to the table.

This should fix it,

local moderation = {}

function moderation:PlrKick(plr, reason)
	if not plr then
		warn("Module has been paused, waiting for player... | Moderation Module Lite")
		task.wait(plr)
		if plr then
			game:GetService("Players"):FindFirstChild(plr)
			if reason ~= nil then
				plr:Kick(reason)
			else
				plr:Kick("You have been kicked from the game, no reasons where specified.")
			end
		end
	end
end

return moderation

Still not working at all. Maybe should I change it to a ‘.’?

Also why are you doing if not player that will just cause the script to not run that bit of code.

I would suggest removing

if not plr then
		warn("Module has been paused, waiting for player... | Moderation Module Lite")
		task.wait(plr)

Can I know why you’re checking the name of a Service? Might be causing the problem.

Removed, yet it’s still not working.

MODULE:

local moderation = {}

function moderation:PlrKick(plr, reason)
		if plr then
			game:GetService("Players"):FindFirstChild(plr)
			if reason ~= nil then
				plr:Kick(reason)
			else
				plr:Kick("You have been kicked from the game, no reasons where specified.")
			end
		end
end

return moderation

CALLING SCRIPT:

local lite = require(game:GetService("ServerScriptService").ModerationModule_Lite)
local plr = game:GetService("Players")

if plr.Name == "achdef" then
	lite.PlrKick("achdef", "idk")
end

Still not. I have changed it…

local lite = require(game:GetService("ServerScriptService").ModerationModule_Lite)
local plr = game:GetService("Players")

if plr:FindFirstChild("achdef") then
	lite.PlrKick("achdef", "idk")
end