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

Ban list not working to ban people. What is the error?

Hey guys, I'm testing out a little with some scripts, and wanted to see if I could do a ban list. Unfortunately, It comes an error when I test. Here are my scripts:

Script1:

`local banList = game.ReplicatedStorage.BanList

local require = require(game.ServerScriptService.ModuleScript)

banList.OnInvoke = function(plr) for i, v in pairs(require(game.ServerScriptService.ModuleScript)) do if v == plr.Name then

		return true
		
	else
		return false
		
	end
end

end`

Script2:

`local banList = game.ReplicatedStorage:WaitForChild("BanList") local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(plr) local PlayerIsBanned = banList:Invoke(plr) if PlayerIsBanned == true then plr:Kick("Sadly, you've been banned from the game" .. plr.Name .. "!")

end

end) `

ModuleScript:

`local banlist = {"Ducksneedhelp", "11uk"}

return banlist ` Can someone help me what the problem is. If you could, Thank you so much then!

2 comments

0

put your code in code block

0

I did, but some came out

1 answer

✓ Accepted answer

A lot of things are messed: For example, you used the keyword 'require' for a variable name, you then re-required the module script in your loop.

I wrote this code for you because it seems you are still on the part of learning where things sort of make sense but you need a push in the right direction. Anyways, we can simplify your code a bit. Here is a quick example:

This is a Module Script in "game.ReplicatedStorage"

local module = {}
	module.bannedIDs = {0, 1111}

	function module:IsBanned(userId)
		return table.find(self.bannedIDs, userId)
	end
return module

bannedIDs stores the userIDs of the players who are banned from the game. Storing the userID is better than their name because names are changeable. We also wrote a method called 'IsBanned' to return an index or nil depending on if the players userID exists in said list.

This is a ServerScript in "game.ServerScriptService"

local banModule = require(game.ReplicatedStorage:WaitForChild('BanModule'))

game.Players.PlayerAdded:Connect(function(player)
	if banModule:IsBanned(player.userId) then
		player:Kick("No u")
	end	
end)

In here, we require the banModule and then call the :IsBanned() method, passing the players userId. If the method returns anything other than nil, the condition will be met and the player will be kicked with a message saying "No u"

As you can see, I removed one of your Script #1 and the BindableFunction and wrote an alternative inside of the module script. I also didn't use a for loop to iterate through the list because the table library exists.

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