Raycast Hitbox 4.01: For all your melee needs!

Does the Raycast Hitbox 4.01 support detection for when a part is touched rather than hit?

Hey! I tried both of you’re solutions @ShadowOfVenus and @Khrrxs but didn’t work, so maybe someone else (or @TeamSwordphin may help me), but I’ve been experiencing some heavy inaccuracy, check the video out please (you can hear the hit sound, different on each weapon, on the few times that hitbox worked): Hitbox inaccuracy

Thank you for reading!

@TeamSwordphin Since I haven’t seen any replies regarding on-touch detection, what part of the module takes care of that?

@Quellet , @MILLENNlA you could easily make one like this

fire this

newHitbox:HitStart

without doing this

newHitbox:HitStop()

then it will work like a on-touch detection

“even in the docs it shows it”

its in 3rd step

1 Like

I see, but when doing so, it either doesn’t damage or does not re-enable itself. It says that HitStop() is required to damage the character again if the player was already hit.

Can you just make a little example code of few lines with a damage function to show how it should be layed out as? Cause I’m really confused by this. :laughing:

For an example: on that sword tool featured in the file, how would I also add touch detection alongside it damaging on activate?

1 Like

UPDATE: I realized that hitboxes work perfectly on dummies, the problem is on players. Can someone assume a solution from this?

UPDATE 2: I FOUND THE PROBLEM :smiley: IT IS THE ACCESSORIES AND HAIR (meshes I guess) IN THE VICTIM’S CHARACTER, DO ANYONE OF YOU KNOW IF THIS HAS ANYTHING TO DO WITH ANY PART OF THE MODULE?

Edit: I’m talking about this issue on this topic.

Thank you for reading!

3 Likes

Roblox is currently down

when its not I will try to do your request, “can’t access roblox studio”

Is there a way to make it not hit players? I’m making a script with blood droplets that make a blood puddle when they hit the ground and they keep hitting my players character and then making puddles on my character. I’m not very experienced in raycasting yet

You need to set up a Raycast filter to ignore the character.

Example
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {char}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
local Hitbox = RaycastHitbox.new(Hitbox)
Hitbox.RaycastParams = raycastParams
2 Likes

I know this may sound dumb, but I can’t hit while moving anymore. Before I used to be able too, now I can’t. I believe that it is an animation bug since it animates the tool, I’m not sure tho. Can anyone help me with this?

Nevermind, I fixed it. It was cause my self hit detection :sweat_smile:

1 Like

Do you have any example to handle player ping issue that effecting the raycast?

What do you mean? Are you handling the Raycast on the server?

Nevermind, It’s fixed already, Thanks to HaxxerVaxxer’s post. I thought it was due to the player high ping.

I just doing some testing and for some odd reason, in studio, when I specifically “Run” the game, the raycast works and it’s visualizing. However, when I actually “Play” the game in studio there is no raycast and nothing visualized. Is anyone else having this problem or know how to fix this?

THANK YOU! i seriously can’t thank you enough, now i don’t have to deal with all of Touched’s problems

1 Like

I’ve made local script version, using 5 parts inside of the weapon which have to be welded to reference as points so its easily adjustable for all you have to do is have a part inside of a Tool that’s called Handle, and 5 parts called “Ray1”, Ray2"… “Ray5”. You get the point. After that you should have something like in the video. You also have to create a serverscript that will respond onserverevent of a remoteevent to actually damage the player. To add, removevent doesnt fire when ray hasn’t hit player, so the server can only really overload if 1000 players hit a player at the same time :smiley: With this module you will lag on 100 or less players just hitting air, promise ,since the server is generating all of the rays even they are not hitting anything important. :smiley:

local runService = game:GetService("RunService")

local Detecting = false

local tool = script.Parent

local Part = {tool:WaitForChild("Ray1"),tool:WaitForChild("Ray2"),tool:WaitForChild("Ray3"),tool:WaitForChild("Ray4"),tool:WaitForChild("Ray5")}

local WS = game:GetService("Workspace")

local Debris = game:GetService("Debris")

local player = game:GetService("Players").LocalPlayer

local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {player.Character,tool}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist

local replicatedStorage = game:GetService("ReplicatedStorage")

local RayHitDetectionEvent = replicatedStorage.RayHitDetection.Hit --create a remote event in a folder called RayHitDetection in replicatedstorage

local RayPart = replicatedStorage.RayHitDetection.Ray --make ray part choose colour and texture rest dont really matter 

local RayCooldown = 1--type in seconds


local positionTable = {}
local SecondPositionTable = {}
local u = 0
local rayDelta = os.time()

local SwingDelta = os.time()

local SwingDelay = 3 --seconds



local function VisualiseNonHitRay(rayOrigin,rayDirection,rayDestination, i)
	
	local part = RayPart:Clone()
	part.Parent = Part[i]

	part.CFrame = CFrame.lookAt(rayOrigin,rayDestination)
	part.Size = Vector3.new(0,.1,(rayOrigin-rayDestination).Magnitude)
	Debris:AddItem(part, .5)
	
end

local function CreateRay(rayOrigin,rayDirection,rayDestination, i)
	
	local raycastResult = workspace:Raycast(rayOrigin, rayDirection, raycastParams)
	
	if raycastResult then
		
		local hitPart = raycastResult.Instance 
		
		if hitPart.Parent then
			
			if hitPart.Parent:FindFirstChild("Humanoid") then
				
				--print("Attacked Humanoid")
				
				if hitPart.Parent == player.Character then
				else
					
					if hitPart.Parent.Humanoid.Health>0 then
					
						RayHitDetectionEvent:FireServer(hitPart.Parent)
						
					end
				end
				
				
				
			end
			
		end
		
		
	else
		
		VisualiseNonHitRay(rayOrigin,rayDirection,rayDestination, i)
		
	end
	
end


function RayHitbox()
	rayDelta=os.time()
	while Detecting==true do 
		
		for i,v in pairs (Part) do
			
			positionTable[i] = v.Position
			
		end
		u=u+1
		
		
		runService.RenderStepped:Wait()
		
		for i,v in pairs (Part) do

			SecondPositionTable[i] = v.Position

		end
		
		for i,v in pairs(positionTable) do
			
			if (v-SecondPositionTable[i]).Magnitude > math.pi then
				
			else
				
				
				CreateRay(v,SecondPositionTable[i]-v,SecondPositionTable[i], i)
				
			end
			
		end
		
		if u == RayCooldown*60 then
			
			
			u=0
			Detecting=false
			coroutine.yield()
			
		end
		
		if os.time()-RayCooldown>rayDelta then
			
			rayDelta=os.time()
			Detecting=false
			coroutine.yield()
			
		end
		
	end
	coroutine.yield()
end



local function Start()
	
	if os.time()-SwingDelay > SwingDelta then

		SwingDelta = os.time()
		
		Detecting = true
		
		local Rays = coroutine.create(RayHitbox)
		
		coroutine.resume(Rays)
		
	end
	
	
	
	
end

tool.Equipped:Connect(function()

		tool.Activated:Connect(Start)

end)

–Edits, just improved a bit of code so you couldn’t press down and keep damaging people

Just use :GetTouchingParts() its more convenient

Turn off CanQuery in accessories so the raycasts from the module will ignore them

1 Like

I did that a couple months ago (right after posting it here) and it worked, thank you anyways!

1 Like