So I am making a game but I am struggling to make a hitbox here's how it looks right now It is off place and it forces me to move and I have no clue why heres the scripts that are being used to. Feel free to request any other scripts or the explorer too. Noob is the only player with this code so I cant rlly show the others as examples. any help is appreciated.
#Hitbox confusion
1 messages · Page 1 of 1 (latest)
you need to Cframe (weld) and clone the hitbox to player
like this?
or am I in the wrong part of the code?
yeah
then when animation end you just use ```lua
Hitbox:Destroy()
print("It worked?")
before It could even destroy it the game broke and it said this
it was as soon as I clicked M1 to spawn the hitbox
Don't use .Touched for hitboxes
Use spatial querying
eg; workspace:GetPartsInParts
i didnt wacht he/she was using touched
** You are now Level 5! **
yeah .touched absolutely sucks for hitbox systems
so how would I replace the .Touched? sorry this is my first time doing a hitbox system for litterally anything so I havent heard of spatial querying
theres another problem
what is it?
can collide is off though?
yeah
cancollide = if part can collide
cantouch = if part can touch
cantouch on do that the hitbox work while you cannot touch it
that did your character bugged
i can provide my personal hitbox function as reference if you want
can you send me a video when you do it?
sure go ahead any help is good with me tbh
** You are now Level 4! **
wait
it should be pretty universal(?) try it/modify some bits of it first though
how you put it like roblox
uhh i uploaded it as a .lua file since discord thought the code was too big
i do have a question abt the code you sent before I modify and take some of it and stuff
sure
would it break in anyway when I change models like in the video almost any tut I got had that problem
okay where does it go?
you fixed it?
the hitbox works by spawning a part in a specific position you provided as a parameter -- then you get to decide what to do with it
Im gonna try to
it goes into ServerScriptServices im assuming right?
yeah
oh yeah remove this if not self._FlowSession then return self end first
it's a module
seeing how you're using the hitbox from earlier on the client (which i dont recommend -- but for the sake of helping you let's focus on fixing the hitbox), put it inside replicatedstorage
im testing javascript on discord
wait do I remove my old hitboxes code? being this one?
waht run services does?
yeah but you can keep alot of it since it's pretty much backwards compatible
local Controller = require(ReplicatedStorage.InteractionsModule)
local Player = game.Players.LocalPlayer
local Character = Player.Character
Controller:Hitbox({
Size = Vector3.new(5, 5, 5), -- hitbox dimensions
Offset = CFrame.new(0, 0, -4), -- position relative to character (negative Z = in front)
Duration = 0.5, -- how long it stays active
Debug = true, -- set true to see the red box
}, Character -- the character to attach the hitbox to
, function(victim)
-- this fires once per character hit
local humanoid = victim:FindFirstChild("Humanoid")
if humanoid then
print(victim.Name, "Hit!")
end
end)
** You are now Level 2! **
also use this one instead
i had to edit stuff just to make sure it works on the client
this is directly the character model btw
there's no need to check if it's a humanoid model
@swift loom what run services does?
how can I get the hitbox to work when the attack animation happens?
service that lets you run stuff on the game's runtime
do a hitbox and clone it
send the code
bc this is what i get and here is the code (it isnt really changed bc I am still looking at it)
the one here
copy and paste it so i can edit it
local CantBeAttacked = {}
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local IntractionsController = require(ReplicatedStorage:FindFirstChild("HitboxController"))
local player = game.Players.LocalPlayer
local playermodel = player.Character or player.CharacterAppearanceLoaded:Wait()
local mouse = player:GetMouse()
local UIS = game:GetService("UserInputService")
local ContextActionService = game:GetService("ContextActionService")
local Freeze_Action = "Freeze"
local m1Script = script:WaitForChild("M1")
local m1BindFunc = m1Script:WaitForChild("Function")
local alt1Script = script:WaitForChild("Alt1")
local alt1BindFunc = alt1Script:WaitForChild("Function")
mouse.Button1Down:Connect(function()
if playermodel.Name == "Noob" then
m1BindFunc:Invoke()
local Hitbox = IntractionsController:Hitbox({
Size = Vector3.new(5, 6, 2.5),
Offset = CFrame(0, 0, -2),
Duration = 0.25,
Debug = true
}, playermodel, function(Victim)
local Humanoid = Victim:FindFirstChild("Humanoid")
if Humanoid and not table.find(CantBeAttacked, Victim.Name) then
table.insert(CantBeAttacked, Victim.Name)
do -- logic stuff
Humanoid.Health -= 10
end
task.wait(0.1)
table.remove(CantBeAttacked, table.find(CantBeAttacked, Victim.Name))
end
end)
end
end)
UIS.InputBegan:Connect(function(input, gameprocess)
if playermodel.Name == "Noob" then
if input.UserInputType == Enum.UserInputType.Keyboard then
local key = input.KeyCode
if key == Enum.KeyCode.E then
alt1BindFunc:Invoke()
end
end
end
end)
make a modulescript in replicatedstorage
and name it "HitboxController"
tell me what it says if there are any errors
just make sure you copy and paste this inside the modulescript
otherwise it wouldn't work
the whole script or just that part?
with this
does the order of the two matter or are they mixed in?
bc nothing happened when I put the first code on top and vise versa
they're not supposed to be mixed in
don't place them both in the same script
replace your original script
what i meant by replace was; delete the whole thing and paste the one i made
so first off sorry for all this stuff your reapeating. but let me make sure I understand. I replace the localscript named Input manager with that code correct? or do I get rid of Inputmanager for a module script in replicated storage?
Don't worry about it
I don't mind at all
So basically;
- Delete everything inside InputManager
- Paste this inside;
local CantBeAttacked = {}
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local IntractionsController = require(ReplicatedStorage:FindFirstChild("HitboxController"))
local player = game.Players.LocalPlayer
local playermodel = player.Character or player.CharacterAppearanceLoaded:Wait()
local mouse = player:GetMouse()
local UIS = game:GetService("UserInputService")
local ContextActionService = game:GetService("ContextActionService")
local Freeze_Action = "Freeze"
local m1Script = script:WaitForChild("M1")
local m1BindFunc = m1Script:WaitForChild("Function")
local alt1Script = script:WaitForChild("Alt1")
local alt1BindFunc = alt1Script:WaitForChild("Function")
mouse.Button1Down:Connect(function()
if playermodel.Name == "Noob" then
m1BindFunc:Invoke()
local Hitbox = IntractionsController:Hitbox({
Size = Vector3.new(5, 6, 2.5),
Offset = CFrame(0, 0, -2),
Duration = 0.25,
Debug = true
}, playermodel, function(Victim)
local Humanoid = Victim:FindFirstChild("Humanoid")
if Humanoid and not table.find(CantBeAttacked, Victim.Name) then
table.insert(CantBeAttacked, Victim.Name)
do -- logic stuff
Humanoid.Health -= 10
end
task.wait(0.1)
table.remove(CantBeAttacked, table.find(CantBeAttacked, Victim.Name))
end
end)
end
end)
UIS.InputBegan:Connect(function(input, gameprocess)
if playermodel.Name == "Noob" then
if input.UserInputType == Enum.UserInputType.Keyboard then
local key = input.KeyCode
if key == Enum.KeyCode.E then
alt1BindFunc:Invoke()
end
end
end
end)
- Next, go to ReplicatedStorage and create a ModuleScript
- Remove everything and paste this inside:
Then name it "HitboxController"
It let me do a attack but crashed and said this
oh oops
** You are now Level 3! **
it works but I do have a question
okay awesome
how do I make a cooldown since I only allow 3 hit combos on M1 at a time
would it just be the same way I did it in the M1 script or where I made the cooldown?
yeah i made it so that i copied how the m1 works on your original script
it lets me spam it like 20 times though do i need to edit the M1 script itself for it to work or just try to add a debounce to the hitbox?
oh you're talking about a different type of cooldown
that's for you to add
🤷♂️ (im getting lazy)
it would be a debounce though right?
yes there's a debounce on the current script that lasts .1 seconds
what is this 💔
lowkey unnecessarily complex
part0 is not for cframes, its for basepart so just remove cframe infront of the hrp
dang this is hitbox prediction?
i always wanted to add it but i'm not good with prediction math
just activate the hitbox module when you play the animation
you can add a debounce
easily
oh i forgot about that
but yeah