RaycastHitbox v4.01 is inconsistent

  1. What do you want to achieve?
    Make a sword that can damage another player.
  2. What is the issue?
    The sword sometimes cannot damage a player.

Video of the issue

  1. What solutions have you tried so far?
    I added more DmgPoints but nothing happened.
    The scripts i used:
    CLIENT (Local script)
local Tool = script.Parent
local Mouse = game.Players.LocalPlayer:GetMouse()
local Hit = script.Parent:WaitForChild("Hit")

function isEquipped()
	if Tool.Parent:FindFirstChild("Humanoid") then
		return true else return false
	end
end

Mouse.Button1Down:Connect(function()
	if not isEquipped() then return end
	Hit:FireServer()
end)

SERVER (SCRIPT)

local Tool = script.Parent
local Handle = Tool.Handle
local Anims = Tool.Anims

local RaycastHitbox = require(game.ServerScriptService.RaycastHitboxV4)
local Hitbox = RaycastHitbox.new(Tool.Hitbox)

local de = false
local canHit = false

config = {
	Damage = 20,
	AttackTime = .1,
	Cooldown = .3
}

Hitbox.OnHit:Connect(function(hit, humanoid)
	if canHit == false then return end
	canHit = false
	if humanoid.Parent ~= script.Parent.Parent then
		humanoid:TakeDamage(config.Damage)
		print("hit")
		local character = humanoid.Parent
		
		local Knockback = Instance.new("BodyVelocity")
		Knockback.P = math.huge
		Knockback.Parent = character:FindFirstChild("HumanoidRootPart")
		Knockback.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
		Knockback.Velocity = character:FindFirstChild("HumanoidRootPart").CFrame.lookVector * -7
		game:GetService("Debris"):AddItem(Knockback, .3)
		task.wait(.35)
	end
	canHit = true
end)

script.Parent.Hit.OnServerEvent:Connect(function(Player)
	if de == false then
		de = true
		local Humanoid = Player.Character.Humanoid
		local AnimationsList = Anims:GetChildren()
		local Selected = Humanoid:LoadAnimation(AnimationsList[math.random(1, #AnimationsList)])
		Selected:Play()

		Hitbox:HitStart()
		wait(config.AttackTime)
		canHit = true
		Humanoid.WalkSpeed = 1
		wait(config.Cooldown)
		Humanoid.WalkSpeed = 16
		Hitbox:HitStop()
		canHit = false
		de = false
	end
end)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

1 Like

I currently work with both the latest-ish public release and an unreleased version that supports Actors so that may change the answer here, but it’s worth noting that RaycastHitbox will:

  • Already enforce that a valid target is only hit once for the duration of the hitbox being active (when you start casting with HitStart), so the debounce is not needed here and may lead to unexpected behaviours from other OnHit connections.

  • If configured (RaycastHitbox supports configuration), already make sure that targets you don’t want to get hit will not get hit. If you set the right configuration, you don’t need to validate that the parent of the Humanoid is not the same as the parent of the tool.

I encourage you to make sure that you have the right setup and have done some debugging. Beyond those gotchas about the resource, there’s not much help you can be given as there’s not much information to go off of here.

2 Likes

thank you for the advice my friend, it helped and it registers 95% of the time now, I’ll just figure the rest out

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