Client:
--{{ Service's }}--
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UserInputService = game:GetService("UserInputService")
--{{ Variables }}--
local M1Tool = script.Parent
local canSendEvent = false
local RemotesFolder = ReplicatedStorage:WaitForChild("Remotes")
if not RemotesFolder then
warn("No Remotes folder: " .. debug.traceback(script.Name, 2)) -- < Provide the ScriptName alongside where it resides.
end
local CombatRemotes = RemotesFolder:WaitForChild("CombatRemotes")
if not CombatRemotes then
warn("No CombatsFolder found: " .. debug.traceback(script.Name, 2)) -- < Provide the ScriptName alongside where it resides.
end
local PrimaryAction = CombatRemotes:WaitForChild("PrimaryAction")
if not PrimaryAction then
warn("No PrimaryAction found: " .. debug.traceback(script.Name, 2)) -- < Provide the ScriptName alongside where it resides.
end
M1Tool.Equipped:Connect(function()
canSendEvent = true
end)
M1Tool.Activated:Connect(function()
if canSendEvent then
PrimaryAction:FireServer()
end
end)
M1Tool.Unequipped:Connect(function()
canSendEvent = false
end)
Server:
--{{ Service's }}--
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local ServerScriptService = game:GetService("ServerScriptService")
--{{ Variables }}--
local ModulesFolder = ServerScriptService["Game[Server]"].Modules
local M1ModuleService = require(ModulesFolder:WaitForChild("M1ModuleService"))
if not M1ModuleService then
warn("M1ModulesService could not be found: " .. debug.traceback(M1ModuleService.Name, 2))
end
local RemotesFolder = ReplicatedStorage:WaitForChild("Remotes")
if not RemotesFolder then
warn("No Remotes folder: " .. debug.traceback(script.Name, 2)) -- < Provide the ScriptName alongside where it resides.
end
local CombatRemotes = RemotesFolder:WaitForChild("CombatRemotes")
if not CombatRemotes then
warn("No CombatsFolder found: " .. debug.traceback(script.Name, 2)) -- < Provide the ScriptName alongside where it resides.
end
local PrimaryAction = CombatRemotes:WaitForChild("PrimaryAction")
if not PrimaryAction then
warn("No PrimaryAction found: " .. debug.traceback(script.Name, 2)) -- < Provide the ScriptName alongside where it resides.
end
local Combo = 0
print("Server is listening to PrimaryAction...")
local lastCall = {} -- < Store the last call(newCall)
PrimaryAction.OnServerEvent:Connect(function(player: Player)
print("Action")
local newCall = tick() -- < Set newCall to when the PrimaryAction is being called.
if lastCall[player.UserId] and newCall - lastCall[player.UserId] <= 0.6 then -- < Check if newCall - the stored newCall is less than 0.6
print("Fired too much by " .. player.Name) -- < If what previously stated is true, it prints the player's name
return -- < Return so the combo and the M1ModuleService doesn't get called.
end
Combo += 1 -- < add 1 to the combo value
if Combo >= 5 then -- < Check if the combo value is more than 5
Combo = 1 -- < Make Combo to 1
end
lastCall[player.UserId] = newCall -- < Insert the new player.userId and the newCall so we can check the difference between newCall and lastCall.
M1ModuleService:attack(player, Combo) -- < Give M1ModuleService the player and the combo number.
end)