Sword Combat System

  1. Combat system of raycast to work properly

  2. Problem
    I’m using a module for the raycasting, and I’m trying to learn sword combat system
    But the problem I’m currently having is There is a chance that the player is gonna hit I’ll say roughly 50-75% work accurately. Then the issue is if the cool downs were to be removed the player will instantly
    die how can I avoid the cooldowns messing with the combat

  3. I’ve tried to make a separate function to check if there is something inside the table but the table either the animation plays every time or doesn’t play at all.

(Script Inside the tool) There are no local scripts needed


--------------------[[ Requiring Raycast Module ]]--------------------
local ClientCast = require(game.ReplicatedStorage.ClientCast)

--------------------[[ Blade Variables/Cooldowns ]]--------------------
local Tool = script.Parent
local Blade = Tool.Blade
local KillPart = Blade
local slash 
--------------------[[ SOUNDS ]]--------------------
local Attack = script.Parent.Blade.Attack
local Swordout = Attack.Parent.Swordout
local swing = Attack.Parent.Swing
local Swordin = Attack.Parent.SwordIn

--------------------[[ [Making The Ray's] ]]--------------------
function GenerateAttachment(Position)
	local Attachment = Instance.new('Attachment')
	Attachment.Name = 'DmgPoint'
	Attachment.Position = Position
	Attachment.Parent = KillPart
end

for i = -1.791, 1.489,.1 do
	GenerateAttachment(Vector3.new(0, i, 0))
end
local ClientCaster = ClientCast.new(KillPart, RaycastParams.new())
--------------------[[ [---------------] ]]--------------------

local Debounce = {} --- Debounce Table Cooldown

local AnimBounce = true   ---- Animations Cooldowns

ClientCaster:Stop() -- Stops The Raycasting Sword 
script.Parent.Equipped:Connect(function()
	Swordout:Play()----- Sword sound taken out
	local  humanoid = script.Parent.Parent:FindFirstChild("Humanoid")
	idle = humanoid:LoadAnimation(script.Idle); idle.Priority = Enum.AnimationPriority.Idle
	idle:Play()---- Idle Animation
	
end)


script.Parent.Activated:Connect(function()
	Swingz()
	ClientCaster:Start()
	Animation()
	ClientCaster.HumanoidCollided:Connect(function(RaycastResult, HitHumanoid)
		if HitHumanoid.Parent ~= Tool.Parent then	
			if Debounce[HitHumanoid] then
				return
			end
			Attack:Play()---- Hit Sound
			local Humanoid = HitHumanoid.Parent:FindFirstChild("HumanoidRootPart")
			local fire =  game:GetService("ReplicatedStorage").Rep.Flames:clone()
			fire.Parent = Humanoid
			Debounce[HitHumanoid] = true --- Tabel Debounce
			HitHumanoid:TakeDamage(15)--- Damage Taken
			Flame(HitHumanoid,fire)---- Player Burning Function passes paramas "HitHuman" = player Fire = Clone to the player
			task.wait(0.10)
			Debounce[HitHumanoid] = false--- Tabel Debounce
			
		end
	end)
end)
----[[By Ignaury]]----

function Animation()--- Animation Swings
	if AnimBounce then
		print(Debounce)
		if Debounce == nil  or Debounce == true then return end
		local  humanoid = script.Parent.Parent:FindFirstChild("Humanoid")
		if not slash then slash  = humanoid:LoadAnimation(script.Animation); slash.Priority = Enum.AnimationPriority.Action end
		slash:Play()
		AnimBounce = false---- Animation CoolDown
		task.wait(0.3)
		AnimBounce = true
	end
end


function Swingz()--- swing sound
	if swing.IsPlaying then return 	--- If the sound is being played then it returns Avoiding Spam sounds
	else
		swing:Play()
	end
end


function Flame(HitHumanoid,fire)--- Flames the player
	local Cool = 0
	game.Debris:AddItem(fire,3)--- Removes the fire

	while Cool <= 30 do --- While loop until cool Is over
		HitHumanoid:TakeDamage(1)
		task.wait(0.1)
		Cool += 1
	end
	task.wait(3)
end


script.Parent.Deactivated:Connect(function()
	ClientCaster:Stop() --- Stop The Ray
end)


script.Parent.Unequipped:Connect(function()
	if slash then slash:Stop() end
	Swordin:play()---- sword sheath
	ClientCaster:Stop()--- Stops The Cast Aka the ray
	idle:Stop()--- stop the idle animation being played
end)

----[[By Ignaury]]----
3 Likes

I also have this issue. Looking forward for a solution to this.

1 Like