#How do I get the "self.HCFrame" and "self.Size" for the touching function

1 messages · Page 1 of 1 (latest)

sullen valley
#

I'm also open to any tips about the way I've formatted the script or just to do things a completely different way

local Debris = game:GetService("Debris")

local Hitbox = {}
Hitbox.__index = Hitbox

function Hitbox.Visualise(HCFrame : CFrame, Size : Vector3, Duration : number)
    local Part = Instance.new("Part", workspace)
    Debris:AddItem(Part, Duration)
    Part.CFrame = HCFrame
    Part.Size = Size

    Part.Anchored = true
    Part.CanCollide = false
    Part.CanQuery = false
    Part.CanTouch = false
    Part.Color = Color3.new(1, 0, 0)
    Part.Material = Enum.Material.ForceField
end

function Hitbox.New(HCFrame : CFrame, Size : Vector3, Owner)
    local NewHitbox = {}
    NewHitbox.HCFrame = HCFrame
    NewHitbox.Size = Size
    NewHitbox.Owner = Owner
    setmetatable(NewHitbox, Hitbox)
    
    Hitbox.Visualise(HCFrame, Size, 0.5)
    return Hitbox
    --print(Hitbox)
end

function Hitbox:Touching()
    print(self.HCFrame, self.Size)
    --[[local Hit = workspace:GetPartBoundsInBox(self.HCFrame, self.Size)
    local HitCharacters = {}
    
    for index, part in Hit do
        if part.Parent:FindFirstChild("Humanoid") then
            if part.Parent ~= self.Owner then
                if not table.find(HitCharacters, part.Parent) then
                    table.insert(HitCharacters, part.Parent)
                end
            end
        end
    end
    
    return HitCharacters]]
end

return Hitbox
#

also how do I give players scripts like sprint scripts but only at certain times

#

I'm doing a lot of shit I don't know how to do someone hold my hand]

#

how would I insert more data underneath a player or should I go about it completely differently

local PlayerGameData = {}

local PGD = {}

function PlayerGameData.new(Player)
    table.insert(PGD, Player)
    
    print(PGD)
end

return PlayerGameData```
shadow ice
#

I would do like this for hitbox

Hitbox.__index = Hitbox
--[[understand that indexing links the objects to the class, so that any object inside the class can index to the same methods]]--

--///USE CONSTRUCTOR JUST TO MAKE BLUEPRINT, DONT INCLUDE FUNCTION IN IT///--

function Hitbox.New(HCFrame : CFrame, Size : Vector3, Owner: Model, Duration: number)
local self = setmetatable({}, Hitbox)
self.HCFrame = HCFrame
self.Size = Size
self.Owner = Owner

return self
end

--[[also i would combine your hitbox visuals with the touching so its in sync so just create one function to initiate the hitbox]]--

function Hitbox:Create()
--you have access to self
end

to use this go in ur script or local script

and first reference ur module then do

local NormalHitbox = HitboxModule.New(HCFrame : CFrame, Size : Vector3, Owner: Model, Duration: number)

local SmallHitbox = HitboxModule.New(HCFrame : CFrame, Size : Vector3, Owner: Model, Duration: number)

now that you created the hitbox, use the create method to actually do something with it

NormalHitbox:Create()

or if u want small hitbox

SmallHitbox:Create()

#

also use : for methods as semicolon indicates self as the first parameter, if you use . (dot) then it wont know which object is calling it

sullen valley