Help With MAKING a SWORD using RAYCASTHITBOX

In case you didn’t know the module that I’m referring to: Raycast Hitbox 4.01: For all your melee needs! - #521 by TeamSwordphin

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.

I also noticed when I put the sword in starter pack, some reason the issue is solved, or if I give the player the sword early on in the game, like 20 seconds in (not when the player is added)

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)
1 Like

Have you put prints in to confirm the logic flows as you expect?

Found the issue, it is whenever the HumanoidRootPart.Position is changed to teleport the players down to the map. It casts the rays not at the handles position but the last y co-ordinate of the player. How would I get around this?

If the ray cast is being done in the module script you could either try changing the code there or contact the originator of the module.

The problem is that the sword works fine, UNTIL I change the Characters (which is using the sword) HumanoidRootPart.position. Is there a better way of teleporting players that i do not know of?

use CFrame, never position for player teleporting. 30 letters

1 Like

So set the CFrame of the HumanoidRootPart, when teleporting players?

HRP.CFrame = Part.CFrame yes

1 Like