Help with raycasts

I have a slash attack it works perfectly fine but I want to delay the raycast so it only hits after the attack finished

local remote = game:GetService("ReplicatedStorage").SlashAttack

local TweenService = game:GetService("TweenService")
local Debris = game:GetService("Debris")

remote.OnServerEvent:Connect(function(plr)
	local Effect = game:GetService("ReplicatedStorage")["slash effect"]:Clone()
	
	local rayOrigin = plr.Character.HumanoidRootPart.Position
	local rayDirection = plr.Character.HumanoidRootPart.CFrame.LookVector 
	local raycastParams = RaycastParams.new()
	raycastParams.FilterDescendantsInstances = {plr.Character}
	raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
	local raycastResult = workspace:Raycast(rayOrigin, rayDirection*25, raycastParams)
	
	local  loc = plr.Character.HumanoidRootPart.CFrame * CFrame.new(0,0,-2)
	Effect.CFrame = loc
	Effect.Parent = workspace
	
	local info = TweenInfo.new(
		2,
		Enum.EasingStyle.Exponential,
		Enum.EasingDirection.Out,
		0,
		false,
		0.5

	)
	local props = {
		CFrame = plr.Character.HumanoidRootPart.CFrame * CFrame.new(0,0,-50)



	}
	local tween = TweenService:Create(Effect,info,props)
	tween:Play()
	
	if raycastResult then
		
		local hitPart = raycastResult.Instance
		print(hitPart.Parent.Name)
		if  hitPart.Parent ~= plr.Character and hitPart.Parent:FindFirstChild("Humanoid") then
			hitPart.Parent.Humanoid:TakeDamage(50)
		end
	end
	
	
	
		Debris:AddItem(Effect, 2)

	
	
	
end)

I found this article helpful, using distance and deltatime to effectively set a speed.

Thank yo u for the suggestion but I somehow found a way to fix it I added a couple of cosmetic things like a magic circle and added a few wait that seemingly fixed it

1 Like