I’m making a fighting game as one would know from the 100’s of other posts i’ve made lol.
When spawning in the hitbox I use a variable called “canconnect” to make sure the hitbox doesn’t spam fire.
When using that, If I were to hit something and then another player does. The other player cannot hit.
I’m using a serverscript in serverscriptservice to do all the connecting stuff. If any experienced people know any alternatives to using canconnect. Or if I should rework it entirely, That would be much appreciated.
Here’s the script w/o canconnects,
local PunchEvent = game.ReplicatedStorage.Events.PunchEvent
local StunModule = require(game.ReplicatedStorage.Modules.Stun)
local stunevent = game.ReplicatedStorage.Events.Stun
local players = game:GetService("Players")
local OnConnect = game.ReplicatedStorage.Events.OnConnect
local GrantKill = require(game.ReplicatedStorage.Modules.DataStores.Kills)
local HitboxModule = require(game.ReplicatedStorage.Modules.Stun["HitboxV.1"])
PunchEvent.OnServerEvent:Connect(function(player)
local character = player.Character
local Humanoid = character:FindFirstChild("Humanoid")
local HumanoidRootPart = character:FindFirstChild("HumanoidRootPart")
local hitbox = HitboxModule.Generate(Vector3.new(3,3,3), Vector3.new(0,0,2.3), character, HumanoidRootPart, 0)
hitbox.Touched:Connect(function(hit)
if hit.Parent ~= Humanoid then
local hithum = hit.Parent:FindFirstChild("Humanoid")
if hithum:GetAttribute("Parry") == true then
local parryanim = Instance.new("Animation")
parryanim.AnimationId = 'rbxassetid://17637392225'
local parrytrack = hithum:FindFirstChild("Animator"):LoadAnimation(parryanim)
parryanim:Destroy()
parrytrack:Play()
StunModule.parry(Humanoid, 2)
elseif hithum:GetAttribute("Parry") == false and hithum:GetAttribute("Blocking") == false then
StunModule.stun(hithum, 0.5, 10)
OnConnect:FireClient(player, hithum)
GrantKill.Kill(player, hithum)
elseif hithum:GetAttribute("Blocking") == true then
print("blocked")
elseif hithum.Health == 0 or hithum.Health < 0 then
print("already dead")
end
end
end)
end)