Roblox Studio Tutorial How to make a simple ability with hitbox and knockback.
Автор: RedwithWhite
Загружено: 2025-06-17
Просмотров: 1902
A simple Roblox script that makes a hitbox when you press E and when it hits you take damage and knockback.
If you don't know what animation events are, watch another video on YouTube, then come back once you understand it.
Local Script:
local plr = game.Players.LocalPlayer
local chr = plr.Character
local hum = chr:FindFirstChildWhichIsA("Humanoid")
local Animator = hum:FindFirstChildWhichIsA("Animator")
local Animation = Animator:LoadAnimation(script.Animations.Animation)
local RootPart = chr:FindFirstChild("HumanoidRootPart")
local hitbox
local UIS = game:GetService("UserInputService")
local CanDoMove = true
----------------HitBox Stuff---------------------------
local hitboxsize = Vector3.new(4,3,3)
local hit_db = false
local hitlist = {}--for attacks to hit multiple players at the same time
----------------------------------------------------------
UIS.InputBegan:Connect(function(input, GPE)
if GPE == false then
if CanDoMove == true and input.KeyCode == Enum.KeyCode.E then
Animation:Play(0,1,1)
end
end
end)
Animation:GetMarkerReachedSignal("Start"):Connect(function()-----When the animation starts
CanDoMove = false
hit_db = false
end)
Animation:GetMarkerReachedSignal("HitBox_On"):Connect(function()-----When the hitbox starts
if hitbox == nil then
hitbox = Instance.new("Part",workspace)
hitbox.Position = RootPart.Position + RootPart.CFrame.LookVector * 5--Position the hitbox
hitbox.Rotation = RootPart.Rotation
hitbox.Shape = Enum.PartType.Block
hitbox.Transparency = 1
hitbox.Color = Color3.fromRGB(255, 0, 0)
hitbox.Size = hitboxsize
hitbox.Material = Enum.Material.Neon
hitbox.CanCollide = false
hitbox.CanTouch = true
hitbox.CanQuery = false
hitbox.CastShadow = false
hitbox.Anchored = false
hitbox.Massless = true
local w = Instance.new("WeldConstraint", hitbox)--weld hitbox to character
w.Part0 = hitbox
w.Part1 = RootPart
hitbox.Touched:Connect(function(Hit)--when the hitbox hits something
--this one will be one tap method
if hit_db == false then
hit_db = true
if Hit ~= nil and Hit.Parent ~= nil and Hit.Parent:FindFirstChildWhichIsA("Humanoid") ~= nil and Hit.Parent ~= chr then--checks to make sure its a character that isnt you
print("THIS IS A CHARACTER")
script.RemoteEvents.Hit:FireServer(Hit.Parent)--send the instance of our enemy to the server so we can apply the damage on the server
end
end
end)
else
hitbox:Destroy()
task.wait(0.01)
hitbox = Instance.new("Part",workspace)
hitbox.Position = RootPart.Position + RootPart.CFrame.LookVector * 5--Position the hitbox
hitbox.Rotation = RootPart.Rotation
hitbox.Shape = Enum.PartType.Block
hitbox.Transparency = 1
hitbox.Color = Color3.fromRGB(255,0,0)
hitbox.Size = hitboxsize
hitbox.Material = Enum.Material.Neon
hitbox.CanCollide = false
hitbox.CanTouch = true
hitbox.CanQuery = false
hitbox.CastShadow = false
hitbox.Anchored = false
hitbox.Massless = true
local w = Instance.new("WeldConstraint", hitbox)--weld hitbox to character
w.Part0 = hitbox
w.Part1 = RootPart
hitbox.Touched:Connect(function(Hit)--when the hitbox hits something
--this one will be one tap method
if hit_db == false then
hit_db = true
if Hit ~= nil and Hit.Parent ~= nil and Hit.Parent:FindFirstChildWhichIsA("Humanoid") ~= nil and Hit.Parent ~= chr then--checks to make sure its a character that isnt you
print("THIS IS A CHARACTER")
script.RemoteEvents.Hit:FireServer(Hit.Parent)--send the instance of our enemy to the server so we can apply the damage on the server
end
end
end)
end
end)
Animation:GetMarkerReachedSignal("HitBox_Off"):Connect(function()-----When the hitbox stops
if hitbox ~= nil then--destroy the hitbox
hitbox:Destroy()
end
end)
Animation:GetMarkerReachedSignal("End"):Connect(function()-----When the move stops
CanDoMove = true
end)
Server script will be in comments. Didn't fit in here :(
Доступные форматы для скачивания:
Скачать видео mp4
-
Информация по загрузке: