So how would I make a ban from SERVER gui?
Not perm from all servers, but ban from the current server they were in.
The “UserBoxBan” is where they put the username
The “Ban” button is when they click that the player that was put is banned.
So how would I make a ban from SERVER gui?
Not perm from all servers, but ban from the current server they were in.
The “UserBoxBan” is where they put the username
The “Ban” button is when they click that the player that was put is banned.
I’d recommend you to have some scripting experience over this, or rather hire someone to do so.
Otherwise, did you search anything to know how to do this? Do you have any current code you can show us, so we can help you?
Now, with those questions out of the away, here’s what we’ll do:
Roblox has a built-in function which can be used on players, this function is the Kick()
function. It’ll kick a player and receives an parameter being the reason for the kick. If otherwise Kick()
is executed without any parameters, it’ll state the game has shutdown.
If Kick()
is used on the client, only the LocalPlayer can be kicked, this means you’ll have to use an Server Sided script - more specifically, an RemoteEvent. You can learn about them here: Remote Functions and Events
But, an quick recap about Remote Events, which will be what we’ll be using here:
RemoteEvents allow client to client, client to server, server to client and server to all clients commucation. And the type of commucation we’ll use here is Client to Server. (E.g:
A player (client) presses the P key to drink an invisibility potion, then a
RemoteEvent
tells the server to make that player invisible to all other players.
)
And so, to do what you want, we will attach an .MouseButton1Click
event to an function. And in that function, we’ll check if the current text of the ‘Ban’ TextBox is a player’s name. If so, run :FireServer()
on an RemoteEvent instance that you’ve created. (This will be done on an Client Sided script)
Meanwhile, you attach an .OnServerEvent
to an function, and in that function, you’ll Kick()
the player. (This wil be done on an Server Sided script.)
Although, doing this wouldn’t permanently make the player stay away from the server. But rather, to do this, you’d attach an .PlayerAdded
event to the Players ‘folder’, and check if the player is the same one that was ‘server banned’. And if so, you’d use :Kick()
on him again.
Your final code would look like this:
-- // LocalScript \\ --
local RemoteEvent
local Button
local TextBox
Button.MouseButton1Click:Connect(function()
local Target = game.Players:FindFirstChild(TextBox.Text)
if Target then
RemoteEvent:FireServer(Target)
end
end)
-- // ServerScript \\ --
local RemoteEvent
RemoteEvent.OnServerEvent:Connect(function(Fired, Target)
Target:Kick('Reason')
coroutine.wrap(function()
game.Players.PlayerAdded:Connect(function(plr)
if plr.Name == Target.Name then
plr:Kick()
end
end)
end)()
end)
You can always search whenever you have a question about something. I hope I was useful. I won’t be available in the next hours - someone else will have to help you.
Also, the system is not perfect, you should also check the UserId, because if the player changes his name, he could bypass this. Although I don’t think it would be necessary. But when making banning systems game-wide, you should definitely do it.
Try adding values to a table with the players userid. When a player joins sort through that table to see if they are banned
Wouldn’t it be easier to not wrap a function and instead have a table of banned users:
local BannedUsers = {} -- StringValues: {"twinqle","twinqle","twinqle"}
and then simply kick any player that joins who is in the table?
local RemoteEvent
RemoteEvent.OnServerEvent:Connect(function(Administrator, Target, Reason) -- Instance (Player), Instance (Player), StringValue
> Target:Kick("Banned by " .. Administrator.Name)
> table.insert(BannedUsers,Target.Name)
end)
game.Players.PlayerAdded:Connect(function(player)
> if table.find(BannedUsers,player.Name) then
>> player:Kick("You are banned from this server.")
> end
end)
If you wanted to also display the reason for the server-ban when the player tries to rejoin, it would be best to use a dictionary for the BannedUsers
variable.
“Ban” is different to being “kicked”. You should clarify what you mean by “ban”. A temporary or permanent ban? The above methods will get you pointed into the right direction for a temporary ban, but depending on what you plan to achieve, you many need to tweak some code on the server.
If you’re considering a permanent ban you should look into storing the ban (Player’s UserId) on the server, through the use of DataStoreService. Here’s a thread that should help:
There are many ways you can go about banning a player, but thats for you to research
If the OP is planning to also implement a way to unban, it would be much more convenient to hold all server-banned players in a table instead of creating an individual thread for each ban created.
where would I put the local script? and server script? (Since he did mention he wouldn’t be able to respond fast anyone can answer this question currently.)
I don’t get how you don’t know the most common basics of where they should be placed… or are you asking what are the references supposed to be? Localscripts go in StarterGui / StarterPack / StarterCharacterScripts, all of them are individual to the client.
Server Scripts should go in ServerScriptService.
I put the server script in server script service. I pasted it. and I get this error:
ServerScriptService.BanTest:4: attempt to index nil with 'OnServerEvent
Because you likely haven’t defined the path to your variables.
local RemoteEvent = Path_To_RemoteEvent