Raycast Hitbox 4.01: For all your melee needs!

FIXED, sorry to bother you!

Collapse

Hi, @TeamSwordphin. I have an issue (see the following picture and a part of the code):
image

...
    if self.Hitbox then self.Hitbox:Deinitialize() end
	self.Hitbox = RaycastModule:Initialize(newWep.Hitbox)
	self.Hitbox.OnHit:Connect(function(_, Humanoid)
		print(Humanoid)
	end)

	for Name, Anim in pairs(Anims) do
		if string.match(Name, "ClassAttack") then
			Anim:GetMarkerReachedSignal("HitStart"):Connect(function()
				self.Hitbox:HitStart() -- Error: function not found. (Line 69)
			end)
			Anim:GetMarkerReachedSignal("HitStop"):Connect(function()
				self.Hitbox:HitStop() -- Error: function not found. (Line 72)
			end)
		end
	end

    repeat wait()
		print(self.Hitbox)
	until false
...

I have a script that swings the sword and when it reaches a certain marker in the animation, it will start/stop the rays. But I get this error:


The first few swings after the character spawns, it doesn’t error, but also no rays. All the swings after that shows the ‘attempt to call a nill value’ error.

My presumptions lies on the fact that the table changes from ‘Hitbox for instance …’ to {…}, which causes the error, because the function isn’t there or isn’t .__indexed. Any idea why this issue happens?

I tried debugging my code from the inside out and it keeps showing this error.

No, I haven’t messed with your module.

EDIT 1: Not parenting the hitbox part (aka the sword) to a descendant in workspace seems to removes the issue, new issue: I don’t have a sword now to swing.

What was the problem: the hitbox wasn’t welded to the sword, so it got destroyed once it reached Workspace’s hell.

so i fixed my loop and i did the stuff u said and its the same as before but the attachments are in the correct place and the rays are just far away

Maybe a shot in the dark, but try setting your NetworkOwner of the Hitbox (where the rays comeout) to nil. (nil = server)

1 Like

it casts from server so i am pretty sure it does in server

1 Like

But have you tried it? An unanchored part created by the server doesn’t calculate it’s physics when there’s a player nearby that can do the calculating for the server.

2 Likes

@TeamSwordphin I just found out that if I jump off cliff, the raycast will not follow sword. Do you know how to solve this. https://gyazo.com/a4b1ba1d4bbbbaa2fcb6d2c44695a97b

Looks like you are anchoring the character, even when you anchor the character they will still retain velocity and this could possible mess up the attachments positions which I’ve seen before with issues like fastcast bullets spawning under the workspace.

So set the characters velocity or now assembly linear velocity to zero when anchored and see if that works

Otherwise it’s a server to client replication issues idk just guessing at this point.

1 Like

I tried changing to velocity to 0. It did not work. I feel it more like it’s a server to client replication issues

It does indeed seem like a server replication issue. If you are using this module server-sided, it’s definitely seeing the sword position differently on the server-side due to latency. Unfortunately there isn’t really a fix for this since technically there is nothing wrong from the module’s standpoint. I wouldn’t worry too much about this if jumping off a cliff isn’t the main part of the game. If you need accuracy, you should use this module client sided and send the hit target to the server as an alternative method (with sanity checks of course).

Yeah, jumping off cliff attack movement isn’t anything important. I was just curious about it.

Hello @TeamSwordphin, great module! I was thinking if you would like to be able to add a thing to your module I made when it is fully finished. It can be used instead of set points/ attachments because this will get the part size and make a grid with positions on it. (The small dots are handle adornments)



1 Like

Hey I Recently was trying to make still hitboxes that would stay in place, but they won’t hit if the player is standing still (sometimes). The red lines appear and they all go throught the player but it won’t detect them. Thanks for helping.

local hitbox = game.Workspace.Part
local hb = RayHB:Initialize(hitbox)

	for i , v in pairs(hitbox:GetChildren()) do
		for i , k in pairs(hitbox:GetChildren()) do
			if v ~= k then
				hb:LinkAttachments(v,k)
			end
		end
	end

	hb:HitStart(.2)

	hb.OnHit:Connect(function(hit,hum)
		print(hum.Parent)
		if game.Players:GetPlayerFromCharacter(hum.Parent) then
			
			game.ReplicatedStorage.Events.ClassEvents.Class2.Ab2:FireServer(hum)
		end
	end)

That’ll be great! I’ll be sure to credit you once it’s finished! I know this will help a lot of people and save a lot of time!


@ncs03082 Looks like there’s a problem on how I wrote the raycastParams for the red line visualizers in the module. It actually does work but for context, the module isn’t ignoring the debug red lines (so therefore they keep hitting the redlines thinking they are actual targets). Try ignoring the terrain in the meantime (which is where the red lines are parented to) and see if it works:

local hb = RayHB:Initialize(hitbox, {workspace.Terrain})

This should be fixed in the next module update. Thanks!

1 Like

The problem that @ncs03082 has, might also happen to many people so I was thinking you should use handle adornments to avoid the rays hitting the debug parts. Secondly, so that people that have other parts in parented to terrain would not have the parts blacklisted.

1 Like

Damn, I was missing out. This really helped me out with my lightsaber system. Thank you for this awesome module! :heart:

1 Like

How do I make the laser rays invisible?

1 Like

it would be nice if u gave a parameter to set the gap between 2 points and i have code for smthg similar to this if it might help u, i used it for making attachments automatically

for i= part.Position.Y - part.Size.Y/2, part.Position.Y + part.Size.Y/2,0.75 do
			for x = part.Position.X-part.Size.X/2,part.Position.X + part.Size.X/2,1 do
			local currattach = Instance.new("Attachment");
			currattach.Name = "DmgPoint";
			currattach.Parent = part;
			currattach.WorldPosition = Vector3.new(x,i,currattach.WorldPosition.Z);
			end
		end

i doubt this will help but here u go

2 Likes

Inside the module, there is a property called DebugMode, turn that to false.

How would you make a functioning sword that is reliable with this module? I tried doing this method, firing the remote from a local script inside a sword. However, it does not work, and I think I found the reason.

Even tho I passed in the ignore argument in local RaycastHitBox:Initialize(handle, dontDamage), the newHitBox.OnHit still fires picking up the humanoid that is told to be ignored, then not allowing any other humanoids to be detected as it can only damage one humanoid at a time. When I take out the ignore argument, the newHitBox.OnHit actually fires, which it does not when the ignore argument is left in RaycastHitbox:Initialize.

Help would be appreciated I am struggling greatly with this issue

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local remoteData = game:GetService("ServerStorage"):WaitForChild("RemoteData")

local SwordDamage = require(ReplicatedStorage.Modules.SwordDamage)
local RaycastHitbox = require(ReplicatedStorage.Modules.RaycastHitbox)
local SwordRaycastPositions = require(ReplicatedStorage.Modules.SwordRaycastPositions)

local cooldown = require(ReplicatedStorage.Modules.Cooldown).cooldownValue

local humanoidsKilled = {}

ReplicatedStorage.Remotes.OnSwing.OnServerEvent:Connect(function(player, handle)
	local playerTeam = nil
	local playerToDamage = nil
	
	if remoteData[player.Name].SwingHandlingDebounce == true then return end
	
	local debounce = remoteData[player.Name].SwingHandlingDebounce
	
	if not debounce.Value then
		print("hello1")
		
		debounce.Value = true
		local character = player.Character or player.CharacterAdded:Wait()
		local dontDamage = {character}
		
		local damage = require(ReplicatedStorage.Modules.SwordDamage)[handle.Parent.Name]
		local newHitBox = RaycastHitbox:Initialize(handle, dontDamage)
		
		newHitBox:SetPoints(handle, SwordRaycastPositions[handle.Parent.Name])
		
		newHitBox.OnHit:Connect(function(hit, humanoid)			
			--just for test purposes on dummies
			
			
			humanoid:TakeDamage(10)
			
			--local playerTeam = player.Team
			
			--local playerToDamage = Players:GetPlayerFromCharacter(humanoid.Parent)
			--if playerToDamage ~= nil then
			--	print(player.Team)
				--if tostring(playerToDamage.Team) == tostring(player.Team) then
				--	print("DO NOT DAMAGE")
				--elseif tostring(playerToDamage.Team) ~= tostring(player.Team) then
				--	print("DAMAGE, THEY ARE THE ENEMY")
				--	humanoid:TakeDamage(damage)
				--end
			--end
			
		--	local leaderstats = player.leaderstats
			--local kills = leaderstats.Kills
			
		--	local enemyTeam = nil
		--	local playerTeam = player.Team
			
			--[[if table.find(humanoidsKilled, humanoid) == nil and humanoid.Health <= 0 then
				table.insert(humanoidsKilled, humanoid)
				kills.Value = kills.Value + 1
			elseif table.find(humanoidsKilled, humanoid) == nil and humanoid.Health >= 0 then
				table.remove(humanoidsKilled, humanoid)
			end]]
		end)
		
		newHitBox:HitStart()
		
		wait(cooldown)
		
		newHitBox:HitStop()
		
		debounce.Value = false
	end
	
end)

At first glance, that should be working correctly. Are you sure you didn’t set the hitbox’s raycastParams to Whitelist by accident somewhere? Have you modified the module in any way?

Does the ‘handle’ ever disappear if the character respawns? The hitbox will still be blacklisting the character’s old model if it doesn’t. You can try modifying the raycastParams of the hitbox directly to see if this fixes it:

local newHitBox = RaycastHitbox:Initialize(handle)

newHitBox.raycastParams = RaycastParams.new()
newHitBox.raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
newHitBox.raycastParams.FilterDescendantsInstances = dontDamage