How to get ban hammer in roblox

Resources Community Tutorials

Hey friends! I see a lot of beginner scripters who want to make a ban hammer, and I thought this could be a cool tutorial to make! Ok, let’s start. :>

Step 1: Ok, so first off publish your game, and go into game settings to enable API services Game settings > Security > Enable studio access to API services

Step 2: Make a new script in ServerScriptService, and write some code like this (code explained in the comments)

local players = game:GetService("Players") -- The player service local dss = game:GetService("DataStoreService") -- The data store service local banSave = dss:GetDataStore("BannedPlayers") -- Our data save to check if the player has been banned players.PlayerAdded:Connect(function(player) -- Fires when a player joins the game pcall(function() -- We do this, so if the data store service is down, the script won't break! if banSave:GetAsync(player.UserId) and banSave:GetAsync(player.UserId) == true then -- If the player has been banned player:Kick("You're banned!") -- Kicks the player from the game with the given message end end) end)

So basically, when you hit the player with the hammer, we will write the ban save, so whenever they join they get kicked! You can change the kick message too, of course.

Step 3: Ok, so now we get into the hammer part! First off, get a model. I’ll just be using a free model, but you can make your own.

Step 4: Okay! Now that we have our model, make sure its in a tool and place it in the StarterPack, for now. Now, edit the tool grip and make sure it isn’t anchored!

Step 5: Make a new script in the hammer! This is the main stuff. (Make a swing animation, first)

local playerService = game:GetService("Players") local dss = game:GetService("DataStoreService") -- The data saving service local banSave = dss:GetDataStore("BannedPlayers") -- Our ban save local hammer = script.Parent -- The tool local animation = hammer:WaitForChild("Animation") -- Insert an animation in the tool local debounce = false -- This is a cooldown! hammer.Activated:Connect(function() local character = hammer.Parent if debounce == false and playerService:GetPlayerFromCharacter(character) and character:FindFirstChild("Humanoid") then end end)

Basically what we did here was create the basis for our ban hammer! So far, we have defined the parts and variables we will be using. Next, we will code the rest of it!

Step 6: Now we code the rest of the weapon!

local playerService = game:GetService("Players") local dss = game:GetService("DataStoreService") -- The data saving service local banSave = dss:GetDataStore("BannedPlayers") -- Our ban save local hammer = script.Parent -- The tool local animation = hammer:WaitForChild("Animation") -- Insert an animation in the tool local debounce = false -- This is a cooldown! hammer.Activated:Connect(function() local character = hammer.Parent if debounce == false and playerService:GetPlayerFromCharacter(character) and character:FindFirstChild("Humanoid") then character.Humanoid.Animator:LoadAnimation(animation):Play() -- Plays the animation local touchFunction touchFunction = hammer.Handle.Touched:Connect(function(hit) -- Fires when the hammer is touched local hitCharacter = hit:FindFirstAncestorOfClass("Model") -- The character we hit local hitPlayer = playerService:GetPlayerFromCharacter(hitCharacter) -- Player we it if hit and hitCharacter and hitPlayer then -- if we hit a player banSave:SetAsync(hitPlayer.UserId,true) -- Saves the ban (Don't do this if you only want to kick them) hitPlayer:Kick("You've been banned!") -- Kicks with the provided message touchFunction:Disconnect() -- Ends the function end end) debounce = true -- Enables cooldown task.wait(0.3) -- You might need to adjust this touchFunction:Disconnect() task.wait(1-0.3) -- The cooldown debounce = false -- Disables cooldown end end)

There! All done. Make sure to only hit someone if you really want to ban them, since unless you program it, they’ll be banned forever!

Conclusion: Well, I hope this has helped some of you! Now you know how to make a ban hammer!

I hope you learned something from this!

Examples:


robloxapp-20220316-1414487.wmv (521.0 KB) (video example)

19 Likes

If you guys want, I can show you how to make the ban hammer available for certain players only, too.

4 Likes

Attyuo2:

wait(1-0.3)

First, use task.wait() instead of wait(). Second, why not just type 0.7 instead of 1-0.3?

Hello mate.

1)Very nice tutorial, good job!

  1. As @HedTB_Dev said above, using ‘wait’ can cause some problems,[not sure why it still exists], use task.wait instead. And, about the delay time, you could simply type 0.7 instead of 1-0.3

Best of wishes!

1 Like

I needed this sooooo badly. Thank you SO MUCH!

Because its easier to change the debounce that way, especially if its a variable. (Which I know its not but you could make it one)

I’ll make sure to take note! Personally, I’ve never had problems with it, but if you want to copy my code, feel free to change it, of course!

I’d recommend you to avoid using ‘wait’, I know it works. But it sometimes can break and somethings alike may occur aswell.

Oh. Has it already had a feature request for it to become deprecated or for it’s functionality to improve? Because this is the first I’ve heard of that. I actually don’t know too much about built-in lua functions. I’ll look into it. Thanks!

How do I make a swing animation like the one you used?

No problems mate! Yeah, every professional dev you’d ask, would tell you to avoid using wait.

Task.wait is better, you can also use runservice when needed.

1 Like

Valkyrop:

Task.wait is better, you can also use runservice when needed.

Yep. Either way is good because according to a Roblox Staff, task.wait() is the exact same thing as RunService:Heartbeat

Use the animation editor. I’m not an animator, so I’m not that good, so you can make way better.

1 Like

Attyuo2:

if banSave:GetAsync(player.UserId) and banSave:GetAsync(player.UserId) == true then

That is redundant, since ‘nil’ and ‘false’ are both basically the same when comparing implicitly. Use the following in place of that:
if banSave:GetAsync(player.UserId) then

Make sure you don’t give the hammer to the wrong person. Otherwise, great resource.

1 Like

Thanks! I made it so its that way just in case I ever added on to it to add an unbanning system, where it would be set to false to unban players.

I’d recommend you adding an option to give a reason for a ban, and add all them into a data, so you or any admin in your game, would be able to see who got banned and why.

Cool tutorial! May use this for my games.

1 Like

Valkyrop:

I’d recommend you adding an option to give a reason for a ban,

No need.

Attyuo2:

hitPlayer:Kick("You've been banned!")

Literally all you have to do is edit the kick message shown above.

1 Like

Yeah, but when you’re in game, you want to instantly ban him with a reason.

I don’t understand what you’re saying.

Also, I don’t think that using a ban hammer should be the one and only way to ban a person. If you would want to customize the reason, use chat commands or an admin panel.

I have to admit that it would be cool the ban hammer had a feature where you could customize the ban reason.

next page →

Toplist

Latest post

TAGs