FastTouched v2 {Improved}

FastTouched

About

  • Fast Touched is a Hitbox Module which allows users to make Hitboxes quick and easy!

Why use it?

  • Efficient and Fast.
  • Beginner Friendly

Where to download?

  • Download will always be in the same thread if it gets updated!

Credits

  • 1christian#0001 { Providing w/ Ideas and helping making the base. }

I’m not providing examples on how to use it’s in the lua script.

local Players = game:GetService("Players")
local Shared = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local HttpService = game:GetService("HttpService")

local HitboxModule = {
    Settings = {
        Event = Shared.Remotes.Hit,
        ShowHitboxes = true,
        HitMessage = "", --// Leave as "" for no message!
    },
    Defaults = {
        Offset = Vector3.new(0,0,0),
        Size = 5,
        Length = 1,
        Damage = 0,
    },
}

---Checks if the part 'Hit' is a client
---@param Hit BasePart
function HitboxModule:IsHuman(Hit: BasePart)
    return (Hit.Parent:FindFirstChildOfClass("Humanoid") and true) or false
end

--- Creates a hitbox for 'Length' seconds on the 'Character'  based on the 'Character' RootPart position multiplied by the offset
---@param Player Player
---@param Character Model
---@param Offset Vector3
---@param Size number
---@param Length number
---@param Damage number
function HitboxModule:CreateHitbox(Player: Player, Character: Model, Offset: Vector3, Size: number, Length: number, Damage: number)

    local Hitboxes = Instance.new("Folder", Character)
    Hitboxes.Name = "ArchMageOwO_"..HttpService:GenerateGUID(false)

    local HeartbeatConnection: RBXScriptConnection|nil
    local TouchedConnection: RBXScriptConnection|nil

    --- Disconnects all RBXScriptConnections and destroys any remaining parts
    local function DisconnectAll()
        if (HeartbeatConnection) then
            HeartbeatConnection:Disconnect()
        end
        if (TouchedConnection) then
            TouchedConnection:Disconnect()
        end

        Hitboxes:Destroy()
    end


    HeartbeatConnection = RunService.RenderStepped:Connect(function(deltaTime)
        local Part: BasePart = Instance.new("Part", Hitboxes)
        Part.CanTouch = true
        Part.CanCollide = false
        Part.CastShadow = false
        Part.Anchored = true 
        Part.CFrame = Character.PrimaryPart.CFrame * (Offset or self.Defaults.Offset)
        Part.Transparency = (self.Settings.ShowHitboxes and 0.5) or 1
        Part.Name = deltaTime * math.random(10000,50000) .. HttpService:GenerateGUID(false)

        TouchedConnection = Part.Touched:Connect(function(Hit: BasePart)
            if self:IsHuman(Hit) then

                if (self.Settings.HitMessage ~= "") then
                    print(self.Settings.HitMessage)
                end

                self.Settings.Event:FireServer(Hit.Parent, Damage) --// Add your own arguements to the event!

                DisconnectAll()
            end
        end)

        Part:Destroy()
    end)

    task.delay(Length or self.Defaults.Length, function()
        DisconnectAll()
    end)

end

return HitboxModule
5 Likes

How is this better than other modules that provide the same function and isn’t this laggy since you are creating a part every RenderStepped and you pass in the parent as the second argument on the Instance.new() function which is laggy more info here.

1 Like

I agree, making a part EVERY FRAME is just very not efficient if you want to use this on multiple parts at once.

Another thing I don’t see how this is better than the normal .Touched when you’re using .Touched in the code, kind of defeats the purpose of this resource.

Yeah. Could have at least done this:

    local Part: BasePart = Instance.new("Part")
    Part.CanTouch = true
    Part.CanCollide = false
    Part.CastShadow = false
    Part.Anchored = true
    Part.Transparency = (self.Settings.ShowHitboxes and 0.5) or 1 

HeartbeatConnection = RunService.RenderStepped:Connect(function(deltaTime)
    local NewPart = Part:Clone();
    NewPart.CFrame = Character.PrimaryPart.CFrame * (Offset or self.Defaults.Offset)
    NewPart.Name = deltaTime * math.random(10000,50000) .. HttpService:GenerateGUID(false)
    NewPart.Parent = Hitboxes;

This still isn’t as efficient because you’re still generating instances every frame.

I am not saying this is the best way to go about doing this. If OP wants to generate an instance every frame they may was well do it the way I did it, it’s a bit more efficient and it’s an easy change.

I mean, I did type “at least”

There is already a module like this exists and it’s much efficient. @kinglol123468 's hitbox module(srry don’t have the link)

I don’t know, why are you asking me? Shouldn’t you be asking the person who made this thread? I simply suggested an easy change to make it at least more efficient than it already is. If you would have taken the time to read my other reply, you’d have learned that I do not endorse this method.

1 Like

Or, just change the part’s cframe every Frame instead of cloning it.

1 Like