Hello! Recently, I have created a client-sided hitbox system that works quite well but there are a few things that I need to have brushed up and cannot quite figure out the solution for
The way that it works is that the client sends a request to the server to fire an ability, the ability then fires from the server to all clients, the client hitbox returns a table of characters it hit to the server to validate them and then back to the client to process the effects on those hit characters.
As I stated earlier, this works great! But there are a few hiccups.
Firstly, whenever a player begins to get knocked away in any direction and the point counter appears, it shows for EVERYONE in the game, not just the person who scored the hit.
Second, I see that it says, “Hit” twice in the output which means the for loop is running more times than it should on each client. I tested this actually and it runs the loop on each client an extra time for each player that’s in the server so that I need some help on as well.
I’m sure, once again, it’s just needing to shuffle around a few things to get it to function in the way I intend it to! I will leave the scripts bellow. (I use a configuration library for my variables so config. is effectively the same as a variable call)
Server Script: (Ability remote call and validation)
config.abilityRemote.OnServerEvent:Connect(function(plr, remote)
remote:FireAllClients(plr)
print("Ability Recieved!")
end)
--Gravity Attributes
config.gravityValidator.OnServerEvent:Connect(function(plr, pChar, vTable)
print("Processing hit.")
local validHit = validationModule.HitValidation(plr, pChar, vTable, 3, 25, 100) --Validation is sent to a module script
config.playGravityVFX:FireAllClients(validHit)
print(validHit)
if #validHit >= 1 then
local pHum = pChar:FindFirstChild("Humanoid")
local hrp = pChar:FindFirstChild("HumanoidRootPart")
local pDirection = hrp.CFrame.LookVector
print(hrp)
for _, vChar in pairs (validHit) do
local vrp = vChar:FindFirstChild("HumanoidRootPart")
task.delay(1.5, function()
knockbackModule.knockbackAttributes(plr, hrp, vChar, vrp, -40, 0, 50, 0) --Knockback attributes of ability
end)
end
print("Hit Validated")
else
return
end
end)
Local Script (VFX Handler. This gets replicated to everyone on the server)
--Gravity VFX
config.gravityVFX.OnClientEvent:Connect(function(plr)
print("Connected to VFX Handler!")
local pChar = plr.Character
local gravAttack = pChar.Humanoid.Animator:LoadAnimation(config.gravityFire)
for _, effect in pairs (config.gravityHand:GetChildren()) do
local effectClone = effect:Clone()
effectClone.Parent = pChar:WaitForChild("LeftHand")
effectClone:Emit(5)
game.Debris:AddItem(effectClone, 1)
end
gravAttack:Play()
gravAttack:GetMarkerReachedSignal("GravEffect"):Connect(function()
config.gravitySnap:Play()
local vTable = hitboxModule.CreateHitbox(pChar, 0, 0, -20, 8, 8, 8)
config.gravityValidator:FireServer(pChar, vTable)
local snapPart = Instance.new("Part")
snapPart.Anchored = true
snapPart.CanCollide = false
snapPart.CanQuery = false
snapPart.CanTouch = false
snapPart.Transparency = 1
snapPart.Size = Vector3.new(1,1,1)
local hitmarkerClone = config.gravityHitmarker:Clone()
hitmarkerClone.Parent = snapPart
snapPart.CFrame = hitboxModule.pos
snapPart.Parent = workspace
hitmarkerClone:Emit(20)
local victimVFX = config.playGravityVFX.OnClientEvent:Connect(function(validHit)
if #validHit == 0 then --If nobody was hit this will fire and then stop the script
print("Nobody was hit!")
return
else
config.gravityCatch:Play()
for _, vChar in pairs (validHit) do --Any victim related effects go here
print("Hit")
local vTorso = vChar:WaitForChild("LowerTorso")
local victim = vChar.Humanoid.Animator:LoadAnimation(config.gravityVictim)
local swirlClone = config.gravitySwirl:Clone()
victim:Play()
swirlClone.Parent = vTorso
swirlClone:Emit(5)
task.delay(1.5, function()
swirlClone:Destroy()
config.gravityRelease:Play()
end)
end
end
end)
task.delay(2, function()
snapPart:Destroy()
victimVFX:Disconnect()
end)
end)
end)
I know the point counter has something to do with shuffling around where the event fires back to the server, but the amount of loops depending on how many players are in the server does not make sense to me.
If you need any more information let me know and thanks!