Raycast Hitbox 4.01: For all your melee needs!

and I meant the effect of having parts appear with the same material as the ground

I did the same post and the guy recommended you to me: How to do raycasting!

What you can do is just get the color of the instance such as; Raycast.Instance.Color

And : Raycast.Instance.Material?

Yes you are correct but it would have to need the material and color.

Is it working for you? Because it doesn’t seem to be working for me

local RaycastHitbox = require(workspace.RaycastHitboxV4)
local punch = script.Parent.Handle:FindFirstChild("Punch")
local swing = script.Parent.Handle:FindFirstChild("Swing")
local Damage = 10
local tool = script.Parent
local Hitbox = RaycastHitbox.new(tool)
wait()
local Character = tool.Parent
debounce = false

local Params = RaycastParams.new()
Params.FilterDescendantsInstances = {Character}
Params.FilterType = Enum.RaycastFilterType.Blacklist

Hitbox.RaycastParams = Params

Hitbox.OnHit:Connect(function(hit, humanoid)
	print(hit.Name)
	
	humanoid:TakeDamage(Damage)
	punch:Play()
end)

function onActivated()
	if debounce == false then
		debounce = true
		Hitbox:HitStart()
		swing:Play() 
		wait(1)
		Hitbox:HitStop() 
		debounce = false
	end
end


script.Parent.Activated:Connect(onActivated)

Even then, I can still hurt myself.

local Character = tool.Parent

You need to define this variable when equipping, not at the top of the script since tools start in backpacks. Do a

print(Character)

to see what I mean. It will return the backpack instead of the actual character.

Example:

local Character

script.Parent.Equipped:Connect(function()
     --- The tool has been parented to the character once equipped, so this is valid now
     Character = tool.Parent

     --- Set our params
     local Params = RaycastParams.new()
     Params.FilterDescendantsInstances = {Character}
     Params.FilterType = Enum.RaycastFilterType.Blacklist

     Hitbox.RaycastParams = Params
end)
1 Like

Before you replied I seemed to have fixed the issue myself, I just had to initialize certain variables on equip, thanks tho!

1 Like

How do you disable the red lines??? It is not working for me. This is my code:

local c = Player.Character
	local Hitbox = RaycastingModule:Initialize(script.Parent, {c})
	Hitbox.Visualizer = false
	Sword.Activated:Connect(function()
		Hitbox:HitStart()
		wait(1)
		Hitbox:HitStop()
	end)
	if Action == "Slash1" then
		
		Hitbox.OnHit:Connect(function(hit, humanoid)
			
			print(hit)
			humanoid:TakeDamage(50)
			Event:FireAllClients("1", hit)
			
		end)
	end

ignore the spacing lol

1 Like

Update to V4 and follow the new syntax guidelines outlined in the main post. You are using old V3 methods.

2 Likes

I was using this module ​in order to make a fake arm that’s being tweened capable of dealing damage. I used the SetPoints method in order to set the points that I want the rays to cast from and this is what ended up happening:
https://gyazo.com/b243cda699601754b0e031379588d267

I originally thought that I made a mistake when setting the location of the points then I instanced some parts at those positions and I got this which is what I wanted.

https://gyazo.com/b937f6056ae72c9c011318465bc1e3f8

I’m assuming this problem is to do with the Arms position and size being tweened but I can’t figure out why it’s happening. What I wanted to happen was for the arm to tween in the forward direction and and the rays to move in the same direction as the arm.

My code is pretty much the same as the intermediate examples on the wiki apart from the following lines

local pointsTable = {Arm.CFrame:PointToWorldSpace(Vector3.new(0,0,-Arm.Size.Z/2)),Arm.CFrame:PointToWorldSpace(Vector3.new(0,Arm.Size.Y/2,-Arm.Size.Z/2)),Arm.CFrame:PointToWorldSpace(Vector3.new(0,-Arm.Size.Y/2,-Arm.Size.Z/2)),Arm.CFrame:PointToWorldSpace(Vector3.new(Arm.Size.X/2,0,-Arm.Size.Z/2)),Arm.CFrame:PointToWorldSpace(Vector3.new(-Arm.Size.X/2,0,-Arm.Size.Z/2))}
newHitbox:SetPoints(Arm, pointsTable)

local goal = {}
goal.Size = Arm.Size + Vector3.new(0,0,80)
goal.Position = Arm.CFrame:PointToWorldSpace(Vector3.new(0,0,-40))
local tweenInfo = TweenInfo.new(0.15,Enum.EasingStyle.Linear,Enum.EasingDirection.In,0,true)
local tween = TweenService:Create(Arm, tweenInfo, goal)
tween:Play()

Thanks for the help in advance

The module will automatically convert the points you give it to it’s object space, so you probably don’t need to use :PointtoWorldSpace. It should work by just using Vectors only.

Example:

local pointsTable = {Vector3.new(0,0,-Arm.Size.Z/2), Vector3.new(0,Arm.Size.Y/2,-Arm.Size.Z/2), Vector3.new(0,-Arm.Size.Y/2,-Arm.Size.Z/2), Vector3.new(Arm.Size.X/2,0,-Arm.Size.Z/2), Vector3.new(-Arm.Size.X/2,0,-Arm.Size.Z/2)}

Let me know if it still doesn’t solve your issue.

Worked perfectly thanks for the help :+1:

1 Like

So exited to be finding this module at the perfect time. I’m creating a combat system and this is exactly what I needed. Kudos!

Changing the mode from Default to PartMode doesnt work
( well it changed just doesnt register), is it because part mode used hit instead of the humanoid part?

RaycastModule always returns the part that it hit, irrespective if they have a humanoid root part or not. PartMode should return the parts hit, but will not return parts it has already hit. What is your code that doesn’t work?

I fixed it, but this is the most amazing module ive ever used.

1 Like

Is there a way to turn off the prints on creating a new hit box? I know the debug log property, but that only works after creating a new one

Lmao I just realized I can edit the module itself, never mind. (You know it’s good when the user forgets it isn’t a default Roblox service)

Well I found the property anyway, but this is awesome. Thanks

1 Like