Hello guys!
I am currently making a lightsaber game.
evry thing is going well but now i need to add blocking and i need help
i want to make it so when this value = enabled
the attackdmg of the player that attacks will be a dif value
i need to detect the players character the hitbox hit…
the attack code
Code:
local remoteEvent = script.Parent.Parent.AttackFolder.Attack1
local tool = script.Parent.Parent
local plr = tool.Parent.Parent
local char = plr.Character
local m1 = script.Parent.Parent.Handle.Hit
local Damage = script.Parent.Parent.dmgfolder.dmg.Value
local RaycastHitbox = require(game.ServerScriptService.RaycastHitboxV4)
local Hitbox = RaycastHitbox.new(script.Parent.Parent["Lightsaber top"].Part)
hitted = false
blockhitted = false
remoteEvent.OnServerEvent:Connect(function()
Hitbox:HitStart()
local Attack = script.Parent.Parent.Parent.Humanoid:LoadAnimation(script.Parent.Parent.Anims.Attack1)
print("Server Attack1!")
Hitbox.OnHit:Connect(function(hit, humanoid)
if hitted then return end
hitted = true
if humanoid.Parent ~= char then
humanoid:TakeDamage(Damage)
m1:Play()
print(hit.Name)
humanoid:LoadAnimation(script.Parent.Parent.Anims.Hit) -- does not work i cant locate the humanoid i hit
end
hitted = false
end)
Attack:Play()
wait(0.3)
Hitbox:HitStop()
end)
wait(2)
m1:Stop()
the attackdmg folder:
i want to use the blockdmg value for this
i have tried many things but all of them don’t seem to work…
local m2 = script.Parent.Parent.Handle.Hitter1
local remoteEvent = script.Parent.Parent.AttackFolder.Attack2
local tool = script.Parent.Parent
local plr = tool.Parent.Parent
local char = plr.Character
local Damage = script.Parent.Parent.dmgfolder.dmg2.Value
local Damage1 = script.Parent.Parent.dmgfolder.Blockdmg.Value
local RaycastHitbox = require(game.ServerScriptService.RaycastHitboxV4)
local Hitbox = RaycastHitbox.new(script.Parent.Parent["Lightsaber top"].Part)
local ls = script.Parent.Parent
hitted = false
remoteEvent.OnServerEvent:Connect(function()
Hitbox:HitStart()
local Attack = script.Parent.Parent.Parent.Humanoid:LoadAnimation(script.Parent.Parent.Anims.Attack2)
print("Server Attack2!")
Hitbox.OnHit:Connect(function(hit, humanoid)
if hitted then return end
hitted = true
if humanoid.Parent ~= char then
if humanoid.Parent:FindFirstChild("ls").Blocking.Value == true then
humanoid:TakeDamage(Damage1)
end
if humanoid.Parent:FindFirstChild("ls").Blocking.Value == false then
humanoid:TakeDamage(Damage)
end
local hit = humanoid:LoadAnimation(game.ReplicatedStorage.Hitanim2)
hit:Play()
m2:Play()
print(hit.Name)
end
hitted = false
end)
Attack:Play()
wait(0.4)
Hitbox:HitStop()
end)
wait(2)
m2:Stop()
To achieve this, you can add a condition to check if the value of the “enabled” variable is true before setting the damage value. Here’s how you can modify your code:
local remoteEvent = script.Parent.Parent.AttackFolder.Attack1
local tool = script.Parent.Parent
local plr = tool.Parent.Parent
local char = plr.Character
local m1 = script.Parent.Parent.Handle.Hit
local dmgFolder = script.Parent.Parent.dmgfolder
local hitbox = require(game.ServerScriptService.RaycastHitboxV4).new(script.Parent.Parent["Lightsaber top"].Part)
local hitted = false
local blockhitted = false
remoteEvent.OnServerEvent:Connect(function()
hitbox:HitStart()
local Attack = script.Parent.Parent.Parent.Humanoid:LoadAnimation(script.Parent.Parent.Anims.Attack1)
print("Server Attack1!")
hitbox.OnHit:Connect(function(hit, humanoid)
if hitted then return end
hitted = true
if humanoid.Parent ~= char then
local damageValue = dmgFolder.dmg.Value
if dmgFolder.enabled.Value == true then
damageValue = dmgFolder.dif.Value
end
humanoid:TakeDamage(damageValue)
m1:Play()
print(hit.Name)
humanoid:LoadAnimation(script.Parent.Parent.Anims.Hit)
end
hitted = false
end)
Attack:Play()
wait(0.3)
hitbox:HitStop()
end)
wait(2)
m1:Stop()
Here, we have added a condition to check if the “enabled” variable in the “dmgfolder” is true, and if it is, we set the “damageValue” to the “dif” value in the “dmgfolder”. Otherwise, we set it to the original “dmg” value.
Note: You may need to modify the variable names and paths according to your specific setup.
local m1 = script.Parent.Parent.Handle.Hit
local remoteEvent = script.Parent.Parent.AttackFolder.Attack2
local tool = script.Parent.Parent
local plr = tool.Parent.Parent
local char = plr.Character
local Damage = script.Parent.Parent.dmgfolder.dmg.Value
local Damage1 = script.Parent.Parent.dmgfolder.Blockdmg.Value
local RaycastHitbox = require(game.ServerScriptService.RaycastHitboxV4)
local Hitbox = RaycastHitbox.new(script.Parent.Parent["Lightsaber top"].Part)
local ls = script.Parent.Parent
hitted = false
remoteEvent.OnServerEvent:Connect(function()
Hitbox:HitStart()
local Attack = script.Parent.Parent.Parent.Humanoid:LoadAnimation(script.Parent.Parent.Anims.Attack1)
print("Server Attack1!")
Hitbox.OnHit:Connect(function(hit, humanoid)
if hitted then return end
hitted = true
if humanoid.Parent ~= char and humanoid.Blocking.Value == 1 then
print("blockhit")
humanoid:TakeDamage(Damage1)
else if humanoid.Parent ~= char and humanoid.Blocking.Value == 0 then
local hit1 = humanoid:LoadAnimation(game.ReplicatedStorage.Hitanim1)
print("Hit")
humanoid:TakeDamage(Damage)
hit1:Play()
end
m1:Play()
print(hit.Name)
end
hitted = false
end)
Attack:Play()
wait(0.4)
Hitbox:HitStop()
end)
wait(2)
m1:Stop()
this will only work if the player has an “IntValue” in the charactershumanoid
now the question is…
how do i make it so when a player is ingame he has a intvalue in hes humanoid?
remoteEvent.OnServerEvent:Connect(function()
hitbox:HitStart()
local Attack = script.Parent.Parent.Parent.Humanoid:LoadAnimation(script.Parent.Parent.Anims.Attack1)
print("Server Attack1!")
hitbox.OnHit:Connect(function(hit, humanoid)
if hitted then return end
hitted = true
if humanoid.Parent ~= char then
local damageValue = dmgFolder.dmg.Value
if dmgFolder.enabled.Value == true then
damageValue = dmgFolder.dif.Value
end
-- Check if the hit player is blocking
local isBlocking = false
if humanoid.Parent:FindFirstChild("Block") ~= nil and humanoid.Parent.Block.Value == true then
isBlocking = true
end
-- Apply normal or block damage depending on whether the hit player is blocking
if isBlocking == true then
humanoid:TakeDamage(dmgFolder.Blockdmg.Value)
else
humanoid:TakeDamage(damageValue)
end
m1:Play()
print(hit.Name)
humanoid:LoadAnimation(script.Parent.Parent.Anims.Hit)
end
hitted = false
end)
Attack:Play()
wait(0.3)
hitbox:HitStop()
end)
``