#Hitbox confusion

1 messages · Page 1 of 1 (latest)

tall quartz
#

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.

lavish lark
#

you need to Cframe (weld) and clone the hitbox to player

tall quartz
#

or am I in the wrong part of the code?

lavish lark
#

yeah

#

then when animation end you just use ```lua
Hitbox:Destroy()

#
print("It worked?")
tall quartz
#

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

lavish lark
#

uhh

#

wait

swift loom
#

Use spatial querying

#

eg; workspace:GetPartsInParts

lavish lark
#

i didnt wacht he/she was using touched

hoary ploverBOT
#

studio** You are now Level 5! **studio

swift loom
#

yeah .touched absolutely sucks for hitbox systems

tall quartz
#

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

lavish lark
#

theres another problem

tall quartz
#

what is it?

lavish lark
#

your hitbox was cancollide on

#

put cancollide off

#

just dont put cantouch off

tall quartz
#

can collide is off though?

lavish lark
#

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

swift loom
lavish lark
#

can you send me a video when you do it?

swift loom
#

hold on

#

let me grab it

tall quartz
#

sure go ahead any help is good with me tbh

hoary ploverBOT
#

studio** You are now Level 4! **studio

swift loom
lavish lark
#

wait

swift loom
#

it should be pretty universal(?) try it/modify some bits of it first though

lavish lark
#

how you put it like roblox

swift loom
#

uhh i uploaded it as a .lua file since discord thought the code was too big

lavish lark
#

i only know ```lua
print("Hi")

#

oh

tall quartz
#

i do have a question abt the code you sent before I modify and take some of it and stuff

swift loom
#

sure

tall quartz
#

would it break in anyway when I change models like in the video almost any tut I got had that problem

swift loom
#

let me check

#

no not at all

tall quartz
#

okay where does it go?

swift loom
#

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

tall quartz
swift loom
#

let me write up a quick snippet on how to use it

#

give me a second

tall quartz
#

it goes into ServerScriptServices im assuming right?

lavish lark
#

yeah

swift loom
#

oh yeah remove this if not self._FlowSession then return self end first

swift loom
lavish lark
#

im testing javascript on discord

tall quartz
lavish lark
#

waht run services does?

swift loom
#
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)
hoary ploverBOT
#

studio** You are now Level 2! **studio

swift loom
#

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

lavish lark
#

@swift loom what run services does?

tall quartz
#

how can I get the hitbox to work when the attack animation happens?

swift loom
lavish lark
#

do a hitbox and clone it

tall quartz
swift loom
#

no i mean like

#

send the original code

swift loom
#

copy and paste it so i can edit it

tall quartz
#

ohhh okay here

swift loom
# tall quartz
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)
swift loom
#

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

tall quartz
#

the whole script or just that part?

swift loom
#

the whole script

#

replace this;

tall quartz
#

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

swift loom
#

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

tall quartz
#

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?

swift loom
#

Don't worry about it
I don't mind at all

So basically;

  1. Delete everything inside InputManager
  2. 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)
#
  1. Next, go to ReplicatedStorage and create a ModuleScript
  2. Remove everything and paste this inside:
#

Then name it "HitboxController"

tall quartz
#

It let me do a attack but crashed and said this

swift loom
hoary ploverBOT
#

studio** You are now Level 3! **studio

swift loom
#

add ".new" next to CFrame

#

so it's CFrame.new(0, 0, -2)

#

and not CFrame(0, 0, -2)

tall quartz
#

it works but I do have a question

swift loom
#

okay awesome

tall quartz
#

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?

swift loom
#

yeah i made it so that i copied how the m1 works on your original script

tall quartz
#

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?

swift loom
#

oh you're talking about a different type of cooldown

#

that's for you to add

#

🤷‍♂️ (im getting lazy)

tall quartz
#

it would be a debounce though right?

swift loom
#

yes there's a debounce on the current script that lasts .1 seconds

tall quartz
#

where is the debounce for the hitboxes located?

#

if there is one

ebon cobalt
#

what is this 💔

ebon cobalt
ebon cobalt
#

i always wanted to add it but i'm not good with prediction math

ebon cobalt
swift loom