How to make blocking for my lightsaber game (uses Raycastv4)

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
image
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:
image

i want to use the blockdmg value for this

i have tried many things but all of them don’t seem to work…

example of what i have tried (failed)

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()

Where is the attackdmg folder? Is it in the character?

Btw thanks for helping :smiley: but

the thing is the “dmgfolder” is litterly a folder where all the values that do damage are located

image

i would like that if the “hit” player is blocking then it receives the “Blockdmg” value and if not the normal dmg is this possible for you?

example of what it looks like rn:

robloxapp-20230325-2208273.wmv (8.5 MB)

its located in the tool and this script is also located in the tool!

i made this code:

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 characters humanoid

now the question is…

how do i make it so when a player is ingame he has a intvalue in hes humanoid?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.