I’m trying to make a combat system. When trying to implement a blocking/parrying system, I found that it had only affected NPC’s and not players. As seen in the server-sided code, I had attempted to create a Forcefield as a way to get around this but Player2 still was damaged.
--//Service Variables\\--
local Debris = game:GetService("Debris")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
--//Modules\\--
local Modules_Folder = ReplicatedStorage.Modules
local Animations = require(Modules_Folder.AnimHandler)
local Effects = require(Modules_Folder.EffectHandler)
local Sounds = require(Modules_Folder.SoundHandler)
local States = require(Modules_Folder.StateHandler)
--//Events\\--
local Events_Folder = ReplicatedStorage.charEvents.Plague
local Basic_Attack_Ev = Events_Folder.L_ATTACK
local Strong_Attack_Ev = Events_Folder.S_ATTACK
local Block_Ev = Events_Folder.BLOCK
local Unblock_Ev = Events_Folder.UNBLOCK
local Dash_Ev = Events_Folder.DASH
--//Workspace\\-
local Hitboxes_Folder = workspace.Hitboxes
--//Subroutines\\--
function create_Part(
Color: Color3,
Transparency: number,
Name: string,
Parent: Instance,
Size: Vector3,
Position: CFrame,
Weld_Part1: Instance
)
local Part = Instance.new("Part")
Part.Color = Color
Part.Transparency = Transparency
Part.Name = Name
Part.Parent = Parent
Part.Size = Size
Part.CFrame = Position
Part.CanCollide = false
local Weld = Instance.new("ManualWeld")
Weld.Part0 = Part
Weld.Part1 = Weld_Part1
Weld.C0 = Weld.Part0.CFrame:ToObjectSpace(Weld.Part1.CFrame)
Weld.Parent = Weld.Part0
return Part
end
function create_BodyVelocity(
Name: string,
Parent: Instance,
MaxForce: Vector3,
Velocity: Vector3,
Duration: number
)
local BodyVelocity = Instance.new("BodyVelocity")
BodyVelocity.Name = Name
BodyVelocity.Parent = Parent
BodyVelocity.MaxForce = MaxForce
BodyVelocity.Velocity = Velocity
if Duration then
Debris:AddItem(BodyVelocity, Duration)
end
end
function HandleHit(Hit_Table, Hit_Character, Damage: number, Hit_SoundID: string)
table.insert(Hit_Table, Hit_Character)
local EM_Humanoid = Hit_Character.Humanoid
local EM_HRP = Hit_Character.HumanoidRootPart
local EM_Status_Folder = Hit_Character:FindFirstChild("Status")
local EM_Action_State = EM_Status_Folder:FindFirstChild("Action")
if not EM_Action_State or EM_Action_State.Value ~= "Block" then
--Adds Stun State
if not EM_Status_Folder:FindFirstChild("Stun") then
States.Add(Hit_Character, "Stun", "Bool", true, 0.4)
end
create_BodyVelocity(
"StunVelocity",
EM_HRP,
Vector3.new(100000, 0, 100000),
((EM_HRP.CFrame.LookVector * -5)*0.5),
0.25
)
EM_Humanoid:TakeDamage(Damage)
Sounds.PlaySound("Hit", Hit_SoundID, 0.25, false, EM_HRP)
end
end
--//Basic Attack\\--
Basic_Attack_Ev.OnServerEvent:Connect(function(Player)
local Character = Player.Character or Player.CharacterAdded:Wait()
local Status_Folder = Character:FindFirstChild("Status")
local HRP = Character.HumanoidRootPart or Character.PrimaryPart
--Checks for 'Status' folder and states.
if not Status_Folder or not Status_Folder:FindFirstChild("Action") then
States.Add(Character, "Action", "String", "None")
elseif not Status_Folder or not Status_Folder:FindFirstChild("Focus") then
States.Add(Character, "Focus", "Number", "None")
elseif not Status_Folder or not Status_Folder:FindFirstChild("Style") then
States.Add(Character, "Style", "Integer", 1)
end
local OverlapParameters = OverlapParams.new()
OverlapParameters.FilterType = Enum.RaycastFilterType.Exclude
OverlapParameters.FilterDescendantsInstances = {Character, Hitboxes_Folder}
local function Hit_Sequence(Action_AnimationID: string, Action_SoundID: string)
States.Set(Character, "Action", "M1", 0.4, "None")
Animations.LoadAnim(Character, "M1", Action_AnimationID, false)
Sounds.PlaySound("M1", Action_SoundID, 0.25, false, HRP)
--//Hitbox Part Settings\\--
local Hit_Color = Color3.new(1, 0, 0)
local Hit_Transparency = 1
local Hit_Size = Vector3.new(4.2, 4.2, 4.2)
local Hit_Pos = HRP.CFrame + (HRP.CFrame.LookVector * 4)
local Hitbox_Part = create_Part(Hit_Color, Hit_Transparency, "Hit", Hitboxes_Folder, Hit_Size, Hit_Pos, HRP)
local Hit_Characters = {}
local Hitbox_SpatialQueery = workspace:GetPartsInPart(Hitbox_Part, OverlapParameters)
for _, Hit in pairs(Hitbox_SpatialQueery) do
local EM_Character = Hit.Parent
if EM_Character:FindFirstChildWhichIsA("Humanoid") and not table.find(Hit_Characters, EM_Character) then
HandleHit(Hit_Characters, EM_Character, 5, "rbxassetid://4471648128")
end
end
Debris:AddItem(Hitbox_Part, 0.4)
end
if Status_Folder.Style.Value == 1 and Status_Folder.Action.Value == "None" or Status_Folder.Action.Value == "M1" then
Hit_Sequence("rbxassetid://74660951512269", "rbxassetid://4958430453")
end
end)
--//Blocking\\--
local Block_WalkSpeed = 4
local WalkSpeed = 16
Block_Ev.OnServerEvent:Connect(function(Player)
local Character = Player.Character or Player.CharacterAdded:Wait()
local Status_Folder = Character:FindFirstChild("Status")
local Humanoid = Character.Humanoid
if Status_Folder then
if Status_Folder:FindFirstChild("State") then
if Status_Folder.State.Value == "None" then
States.Set(Character, "State", "Block")
local ForceField = Instance.new("ForceField")
ForceField.Name = "Invincibility"
ForceField.Parent = Character
ForceField.Visible = false
Animations.LoadAnim(Character, "Block", "rbxassetid://115553859220057", true)
Humanoid.WalkSpeed = Block_WalkSpeed
end
else
States.Add(Character, "State", "String", "Block")
local ForceField = Instance.new("ForceField")
ForceField.Name = "Invincibility"
ForceField.Parent = Character
ForceField.Visible = false
Animations.LoadAnim(Character, "Block", "rbxassetid://115553859220057", true)
Humanoid.WalkSpeed = Block_WalkSpeed
end
end
end)
Unblock_Ev.OnServerEvent:Connect(function(Player)
local Character = Player.Character or Player.CharacterAdded:Wait()
local Status_Folder = Character:FindFirstChild("Status")
local Humanoid = Character.Humanoid
if Status_Folder then
if Status_Folder:FindFirstChild("State") then
if Status_Folder.State.Value == "Block" then
States.Set(Character, "State", "None")
Animations.RemoveAnim(Character, "Block", "rbxassetid://115553859220057")
if Character:FindFirstChild("Invincibility") then Character.Invincibility:Destroy() end
Humanoid.WalkSpeed = WalkSpeed
end
end
end
end)