Help! I’m using the Raycast Hitbox module. My problem is that hitboxes usually stop working or work pretty bad (I think it happens after I died and recovered, since I use a ragdoll system).
Also (it hasn’t necessarily nothing to do with the previous problem, but it may), this error usually shows up on the HitBox:Stop() line if I quickly unequip the tool once activated: “Players.HaxxerVaxxer.Backpack.Fists.HScript:54: attempt to call a nil value”.
CODE (I use it in a lot of tools, this one is just an example, the one I use to script the melee fists):
local health_module = require(game:GetService("ServerStorage").ModuleLibrary.HealthModule)
local Damage = script.Parent.Configuration.Damage.Value
local Tool = script.Parent
local Handle = Tool:WaitForChild("Handle")
local Character = Tool.Parent
local RaycastHitbox = require(Tool.RaycastHitboxV4)
local Hitbox
local dodgeremote = game.ReplicatedStorage.Dodge
local punch2 = script.Parent.Punch2
local punch2v = false
local swing = script.Parent.Handle.Swing
local hit = script.Parent.Handle.Hit
local Players = game:GetService("Players")
local Debris = game:GetService("Debris")
local RunService = game:GetService("RunService")
ToolEquipped = false
Tool.Enabled = true
--function IsTeamMate(Player1, Player2)
-- return (Player1 and Player2 and not Player1.Neutral and not Player2.Neutral and Player1.TeamColor == Player2.TeamColor)
--end
punch2.OnServerEvent:Connect(function()
punch2v = true
end)
function Activated()
if not Tool.Enabled or not ToolEquipped or not CheckIfAlive() then
return
end
if punch2v == true then
Tool.Enabled = false
Hitbox:HitStart()
swing:Play()
local Tick = RunService.Stepped:wait()
local char = Tool.Parent
wait(0.3)
swing:Play()
wait(0.3)
Hitbox:HitStop()
punch2v = false
wait(0.2)
Tool.Enabled = true
else
Tool.Enabled = false
Hitbox:HitStart()
swing:Play()
local Tick = RunService.Stepped:wait()
local char = Tool.Parent
wait(0.6)
Hitbox:HitStop()
wait(0.2)
Tool.Enabled = true
end
end
function Blow(Hit)
if not Hit or not Hit.Parent or not CheckIfAlive() or not ToolEquipped then
return
end
local RightArm = Character:FindFirstChild("Right Arm") or Character:FindFirstChild("RightHand")
if not RightArm then
return
end
local RightGrip = RightArm:FindFirstChild("RightGrip")
if not RightGrip or (RightGrip.Part0 ~= Handle and RightGrip.Part1 ~= Handle) then
return
end
local character = Hit.Parent
if character == Character then
return
end
local humanoid = character:FindFirstChildOfClass("Humanoid")
if not humanoid or humanoid.Health == 0 then
return
end
local player = Players:GetPlayerFromCharacter(character)
if player and (player == Player) then
return
end
if character.HumanoidRootPart.Dodging.Value == false then
health_module.TakeClampedDamage(humanoid,Damage)
hit.Parent = character.UpperTorso
hit:Play()
else
if character.HumanoidRootPart.Dodging.Value == true then
dodgeremote:FireClient(player)
end
end
end
function CheckIfAlive()
return (((Player and Player.Parent and Character and Character.Parent and Humanoid and Humanoid.Parent and Humanoid.Health > 5 and Torso and Torso.Parent) and true) or false)
end
function Equipped()
Tool.Handle.CanCollide = false
Character = Tool.Parent
Player = Players:GetPlayerFromCharacter(Character)
Humanoid = Character:FindFirstChildOfClass("Humanoid")
Torso = Character:FindFirstChild("Torso") or Character:FindFirstChild("HumanoidRootPart")
if not CheckIfAlive() then
return
end
ToolEquipped = true
Hitbox = RaycastHitbox.new(Tool)
Hitbox.DetectionMode = RaycastHitbox.DetectionMode.Default
Hitbox.Visualizer = false
Hitbox.OnHit:Connect(Blow)
end
function Unequipped()
Tool.Handle.CanCollide = true
Hitbox:Destroy()
ToolEquipped = false
end
Tool.Activated:Connect(Activated)
Tool.Equipped:Connect(Equipped)
Tool.Unequipped:Connect(Unequipped)
Thank you for reading!