I have no big skill in this but, u can make a hitbox part in front of character (which has cancollide = false, and transparency = 1), and then make a system when upon pressing desired button it checks if player touches the hitbox part, if player does: deal damage, if not: do nothing
You need to separate your code more than in guns, the simpliest option is to find what guns and melee shares in common:
They can be equipped
They can be held by player
They react to inputs
They perform actions depending on inputs
This way we can create weapon as our base, remember that if you don’t plan to add option to create your own custom interactions, simple InputToFunction map will do, save it in tool data module
Now, you can simply check what input you have received, but first of all, we need to get weapon
local Weapon = Player:GetCurrentWeapon()
if not Weapon then
return
end
local ActionName = InputToFunction[Input]
if not ActionName then
return
end
Weapon:Action(ActionName, ...)
Rest is making class for each gun or melee weapon, and adding action methood, it will call other methoods
function Gun:Action(ActionName: string, ...: any)
if not self[ActionName] then
return
end
self[ActionName](self, ...)
end
function Gun:Use(Hit: BasePart)
print("Hitted:", Hit)
self.Ammo -= 1
if self.Ammo <= 0 then
self:Reload()
end
end