local module = {}
module.Hitbox = function(Character:Model, CFrameOffset:CFrame, Size:number, Damage:number, BlockDamage:number. VfxPart:BasePart)
local Hrp = Character:FindFirstChildOfClass("Humanoid").RootPart
local player = game.Players:GetPlayerFromCharacter(Character)
local leaderstats = player:WaitForChild("leaderstats")
local BlockValue = leaderstats.BlockValue
local Hitbox = workspace:GetPartBoundsInBox(Hrp.CFrame * CFrameOffset, Vector3.one * Size)
local Filtered = {}
for _, Parts in Hitbox do
local PossibleCharacter = Parts.Parent
if PossibleCharacter == Character or table.find(Filtered, PossibleCharacter) or not PossibleCharacter:IsA("Model") then continue end
local Humanoid = PossibleCharacter:FindFirstChildOfClass("Humanoid")
if not Humanoid then continue end
local VfxClone = VfxPart:Clone()
VfxClone.CFrame = Humanoid.RootPart.CFrame
VfxClone.Parent = workspace
if PossibleCharacter:GetAttribute("IsBlocking") == true and PossibleCharacter:GetAttribute("Parrying") == false and PossibleCharacter:GetAttribute("IsGaurdBroken") == false then
BlockValue.Value = BlockValue.Value - BlockDamage
print(BlockValue)
end
if PossibleCharacter:GetAttribute("IsBlocking") == false and PossibleCharacter:GetAttribute("Parrying") == false and PossibleCharacter:GetAttribute("IsGaurdBroken") == false then
Humanoid:TakeDamage(Damage)
PossibleCharacter:SetAttribute("Stunned", true)
task.wait(1)
PossibleCharacter:SetAttribute("Stunned", false)
end
if PossibleCharacter:GetAttribute("IsBlocking") == true and PossibleCharacter:GetAttribute("Parrying") == true and PossibleCharacter:GetAttribute("IsGaurdBroken") == false then
local KatanaParry = hum:LoadAnimation(game:GetService("ReplicatedFirst").Animations.KatanaParry)
KatanaParry:Play()
end
table.insert(Filtered, PossibleCharacter)
task.delay(0.5, game.Destroy, VfxClone)
end
table.clear(Filtered)
end
return module
oh ill do that now, also how do I reference the possiblecharacters player, like I want to get there leaderstats, do I just do PossibleCharacter.Player:waitforchild("leaderstats)?
Do it the same way you did for the character parameter. Use the Players:GetPlayerFromCharacter function but it might return nil if you’re hitting an NPC
local player = game:GetService("Players").LocalPlayer
local chr = player.Character or player.CharacterAdded:Wait()
local rs = game:GetService("ReplicatedStorage")
local stunnedevent = rs:WaitForChild("StunnedEvent")
local hum = chr:WaitForChild("Humanoid")
local leaderstats = player:WaitForChild("leaderstats")
local BlockValue = leaderstats.BlockValue
chr:GetAttributeChangedSignal("Stunned"):Connect(function()
local stunned = chr:GetAttribute("Stunned")
if stunned == true then
hum.WalkSpeed = 0
hum.JumpPower = 0
local Stunanim = game:GetService("ReplicatedFirst").Animations.StunAnim
local StunTrack = chr.Humanoid:LoadAnimation(Stunanim)
StunTrack:Play()
StunTrack.Looped = false
print("player is stunned")
else
print("player is not stunned")
end
end)
chr:GetAttributeChangedSignal("Stunned"):Connect(function()
local stunned = chr:GetAttribute("Stunned")
if stunned == false then
print("player is Unstunned")
task.wait(0.5)
print("Unstunned")
hum.WalkSpeed = 16
hum.JumpPower = 50
else
print("not stunned")
end
end)
chr:GetAttributeChangedSignal("IsGaurdBroken"):Connect(function()
local GuardBroken = chr:GetAttribute("IsGaurdBroken")
if GuardBroken == true then`
hum.WalkSpeed = 0
hum.JumpPower = 0
--local Stunanim = game:GetService("ReplicatedFirst").Animations.StunAnim
--local StunTrack = chr.Humanoid:LoadAnimation(Stunanim)
--StunTrack:Play()
--StunTrack.Looped = false
--print("player is stunned")
end
end)
chr:GetAttributeChangedSignal("IsGaurdBroken"):Connect(function()
local GuardBroken = chr:GetAttribute("IsGaurdBroken")
if GuardBroken == false then`
hum.WalkSpeed = 16
hum.JumpPower = 50
--local Stunanim = game:GetService("ReplicatedFirst").Animations.StunAnim
--local StunTrack = chr.Humanoid:LoadAnimation(Stunanim)
--StunTrack:Play()
--StunTrack.Looped = false
--print("player is stunned")
end)
end
BlockValue.Changed:connect(function(plr)
if BlockValue.Value > 100 then
BlockValue.Value = 100
end
if BlockValue.Value == 0 then
chr:SetAttribute("IsGaurdBroken", true)
task.wait(2)
chr:SetAttribute("IsGaurdBroken", false)
end
end)
There are two issues with this event. First, there’s a backtick character after “then” and the closing parenthesis should be on the second end not the first.
Fixed event:
chr:GetAttributeChangedSignal("IsGaurdBroken"):Connect(function()
local GuardBroken = chr:GetAttribute("IsGaurdBroken")
if GuardBroken == false then
hum.WalkSpeed = 16
hum.JumpPower = 50
--local Stunanim = game:GetService("ReplicatedFirst").Animations.StunAnim
--local StunTrack = chr.Humanoid:LoadAnimation(Stunanim)
--StunTrack:Play()
--StunTrack.Looped = false
--print("player is stunned")
end
end)
Also, your code is kind of repetitive… You know you could do the if statements in one event right? For example, when the stunned attribute changes you don’t need to connect to it twice. You could evaluate it using one if and else statement