Hello! Recently, I have been working on a new hitbox system that allows me to have a bit more control over what I can do with it and it’s been going great, I’m near the end of implementation! There’s one problem standing in my way for the time being and that is my hitbox only hitting one player at a time. Well, not really, “hitting” them one at a time, the way my system works is that it creates the hitbox locally, then sends a validation check to the server and then sends it to a VFX handler, but it seems like the validation check is only running once.
There’s quite a few moving parts going on in making this, but I do believe it is something at fault with the validator check being a boolean statement instead of a table like what I used to run it as before. Since I do not fully understand the problem, I will send what I believe is needed and if more information is required, (such as the hitbox module) I would be happy to provide it.
Ability Activation: (Local Script)
local UIS = game:GetService("UserInputService")
local RS = game:GetService("ReplicatedStorage")
local SS = game:GetService("ServerStorage")
local PLRS = game:GetService("Players")
local hitboxModule = require(RS:WaitForChild("HitboxCreator"))
local remotes = RS:WaitForChild("Remotes")
local slamRemotes = remotes:WaitForChild("Slam")
local slamValidator = slamRemotes:WaitForChild("SlamValidator")
local slamVFX = slamRemotes:WaitForChild("SlamVFX")
local plr = PLRS.LocalPlayer
local pChar = plr.Character
local pHum = pChar:WaitForChild("Humanoid")
local hrp = pChar:WaitForChild("HumanoidRootPart")
local cooldown = 1
local canUseAbility = true
UIS.InputBegan:Connect(function(input, gameProcessed)
if gameProcessed then return end
if input.KeyCode == Enum.KeyCode.Q then
slamVFX:FireServer(plr)
task.delay(1.2, function()
local hitbox = hitboxModule.CreateHitbox()
hitbox.HitboxMode = "Constant"
hitbox.Size = Vector3.new(10, 10, 10)
hitbox.Offset = CFrame.new(0, 0, 0)
hitbox.CFrame = hrp.CFrame
hitbox.Transparency = 0.5
hitbox:StartHitbox()
hitbox.HitPlayer:Connect(function(hitPart, vHum)
slamValidator:FireServer(hitPart, vHum)
end)
task.delay(1, function()
hitbox:DestroyHitbox()
end)
end)
end
end)
Ability Validator: (Server Script)
--Begins VFX for Slam and validates the hit
config.slamVFX.OnServerEvent:Connect(function(plr)
local pChar = plr.Character
config.slamVFX:FireAllClients(plr)
--If the hit is valid it gets sent to the VFX handler
local validator = config.slamValidator.OnServerEvent:Connect(function(plr, hitPart, vHum)
print("Checking hit")
local validHit = validationModule.HitValidation(plr, hitPart, vHum, 1.5, 10, 360)
--config.slamValidator:FireAllClients(validHit)
if validHit == true then
local pChar = plr.Character
local hrp = pChar:WaitForChild("HumanoidRootPart")
local vChar = vHum.Parent
local vrp = vChar:FindFirstChild("HumanoidRootPart")
local vPos = vrp.Position
task.delay(0, function()
knockbackModule.knockbackAttributes(plr, hrp, vChar, vrp, 10, 0, 40, 0)
print("Awarding points to "..plr.Name)
end)
end
end)
task.delay(2, function()
validator:Disconnect()
end)
end)
Validator Module: (Module Script)
local module = {}
local debounce = {}
local RS = game:GetService("ReplicatedStorage")
local SS = game:GetService("ServerStorage")
local PLRS = game:GetService("Players")
function module.HitValidation(plr, hitPart, vHum, c, m, a)
local pChar = plr.Character
warn(pChar.Name.. " has been sent to the hit validator along with the table.")
local cooldown = c
local validHit = false
if plr then
if table.find(debounce, plr.Name) ~= nil then --Debounce cooldown so exploiters cannot spam the server with requests
print("Under debounce!")
else
print("Ability casted!")
table.insert(debounce, plr.Name)
local hrp = pChar:FindFirstChild("HumanoidRootPart")
local pos = hrp.Position
local pDirection = hrp.CFrame.LookVector
local vChar = vHum.Parent
local vrp = vChar:FindFirstChild("HumanoidRootPart")
local vPos = vrp.Position
local magCheck = (vPos - pos)
local distance = magCheck.Magnitude --Gets distance between the players
local normalizedDist = magCheck.Unit --Normalizes that distance number
local dot = pDirection:Dot(normalizedDist) --Normalizes look vector
local radAngle = math.acos(dot) --Finds the angle between the vrp and player look direction
local degAngle = math.deg(radAngle) --Converts above into an angle
if distance <= m and degAngle <= a and vChar then --Validation check
vChar.Humanoid:TakeDamage(10)
validHit = true
else
validHit = false
end
--[[for _, vChar in pairs (vTable) do --Checks if hit was actually valid
local vrp = vChar:FindFirstChild("HumanoidRootPart")
local vPos = vrp.Position
local magCheck = (vPos - pos)
local distance = magCheck.Magnitude --Gets distance between the players
local normalizedDist = magCheck.Unit --Normalizes that distance number
local dot = pDirection:Dot(normalizedDist) --Normalizes look vector
local radAngle = math.acos(dot) --Finds the angle between the vrp and player look direction
local degAngle = math.deg(radAngle) --Converts above into an angle
if distance <= m and degAngle <= a and vChar and not table.find(validHit, vChar) then --Validation check
table.insert(validHit, vChar) --Validates what character was hit
vChar.Humanoid:TakeDamage(10)
else
end
end]]
task.delay(cooldown, function() --Removes player from debounce table after cooldown
debounce[table.find(debounce, plr.Name)] = nil
end)
end
return validHit --Returns valid hits bool to the server for processing
end
end
return module