Heya Everyone!!
I’m working on a simple modular framework inspired by EgoMoose’s FPS framework. I’m wondering how I would implement a debounce inside of the framework. How the framework works is that whenever a player equips an item, it’ll cause the module to get the settings module inside of the item which, of course, contains all the information of the gun including Firerate
. (Which is self explanatory)
I’m wondering how I would be able to include Firerate to it.
--[[SERVICES]]--
local ReplicatedStorage = game:GetService("ReplicatedStorage")
--[[FOLDERS]]--
local RemoteEvents = ReplicatedStorage:WaitForChild("RemoteEvents")
--[[MODULE]]--
local BaseGunModule = {}
BaseGunModule.__index = BaseGunModule
function BaseGunModule:Equip(Weapon)
self.Settings = require(Weapon:WaitForChild("Settings"))
end
function BaseGunModule:Fire(Wielder, A, B)
--//Firerate/Sanity Checking?
--//?
--//Checking to see if the gun has enough ammo
if self.Settings.AmmoHold >= 1 then
--//Firing the gun
self.Settings.AmmoHold -= 1
print("Remaining ammo: "..self.Settings.AmmoHold)
local RaycastParam = RaycastParams.new()
RaycastParam.FilterDescendantsInstances = {Wielder}
RaycastParam.FilterType = Enum.RaycastFilterType.Exclude
local Raycast = workspace:Raycast(A.Position, (B - A.Position).Unit * 5000, RaycastParam)
local RaycastInstance = Raycast.Instance
if RaycastInstance then
local Humanoid = RaycastInstance.Parent:FindFirstChildWhichIsA("Humanoid")
if not Humanoid then
--//The raycast didn't hit a humanoid.
return
end
if Humanoid and Humanoid.Health >= 1 then
Humanoid:TakeDamage(self.Settings.BaseDamage)
print(RaycastInstance.Parent.Name.." has taken "..self.Settings.BaseDamage.." damage.")
RemoteEvents.Fire:FireServer(Humanoid, self.Settings.BaseDamage)
end
end
else
print("Does this even work")
self:Reload()
end
end
function BaseGunModule:Reload()
print("Oh it does, cool.")
--//Reloading the gun if we have enough ammo.
if self.Settings.AmmoContain >= 1 then
self.Settings.AmmoHold += 6
self.Settings.AmmoContain -= 6
else
warn("Find a refill station. You do not have any ammo remaining.")
end
print("Remaining ammo: "..self.Settings.AmmoContain)
end
return BaseGunModule