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)