I was making a combat system. While I was doing that I was working on my blocking system I encounterd a problem. So basiclly I got all the player descendants and I checked if the one desecndant of player is a bool value. If it is then I check if that value is true of false. If it is true, then that means the other player is blocking and then the damage I do is 1, if blocking is false, then the damage I do is 2.5.
PROBLEM: It only seems to be sticking with the regular damage. It isn’t checking if the player is blocking or not everytime I click.
Here is the script:
local combat = script.Parent
local ReplicatedStorage = game.ReplicatedStorage
local CombatEvent = ReplicatedStorage.CombatEvent
local equipped = false
local damage = 2.5
local BlockDamage = 1
combat.Equipped:Connect(function()
equipped = true
print(equipped)
character = combat.Parent
--local ourPlayer = game.Players:GetPlayerFromCharacter(character)
end)
combat.Unequipped:Connect(function()
equipped = false
print(equipped)
end)
local function checkIfHitAndBlocking()
for i,player in pairs(game.Workspace:GetChildren()) do
if player:IsA("Model") then
if player.Humanoid and player.HumanoidRootPart then
if player ~= character then
print("model with humanoid found")
local playerHumanoidRootPart = player.HumanoidRootPart
local ourHumanoidRootPart = character.HumanoidRootPart
local magnitude = (ourHumanoidRootPart.Position - playerHumanoidRootPart.Position).Magnitude
local unit = (ourHumanoidRootPart.Position - playerHumanoidRootPart.Position).Unit
local dot = unit:Dot(character.Head.CFrame.LookVector)
if magnitude <= 2 and dot <= 0.5 then
local desecandants = player:GetDescendants()
for i, desecandant in pairs(desecandants) do
if desecandant:IsA("BoolValue") then
local PlayerIsBlocking = desecandant
if PlayerIsBlocking.Value == true then
player.Humanoid:TakeDamage(damage)
elseif PlayerIsBlocking.Value == false then
player.Humanoid:TakeDamage(BlockDamage)
end
end
end
end
end
end
end
end
end
CombatEvent.OnServerEvent:connect(checkIfHitAndBlocking)