I’m trying to test a hitbox for a sword of mine but, for the past few minutes I keep getting the same error.
"ServerScriptService.SwordCombat.CombatHandler:56: invalid argument #2 (Vector3 expected, got nil) "
apparently the problem is this line
hitbox.CFrame = humrp.CFrame * CFrame.new(0,0,0) * handler.SwordHitboxes[sequence]
``` (Line 56 on the Module Script)
I've searched around Google and the Forums themselves and haven't found anything that could help with my problem.
Main Script
```lua
local rp = game:GetService("ReplicatedStorage")
local combat = rp:WaitForChild("SwordCombat")
local handler = require(script.CombatHandler)
combat.OnServerEvent:Connect(function(Player, sequence)
local character = Player.Character
local h = character.Humanoid
local humrp = character.HumanoidRootPart
local sword = character:FindFirstChild("Sword")
if sword then
local plrAnim, swordAnim, length = handler.getAnimation(h,sword.Controller, sequence)
plrAnim:Play()
swordAnim:Play()
plrAnim:GetMarkerReachedSignal("Hit"):Connect(function()
handler.Attack(Player,character,humrp,sequence)
end)
task.delay(length, function()
combat:FireClient(Player)
end)
end
end)
Module Script
local Animations = script:WaitForChild("Animations")
local plr = Animations.plr
local swrd = Animations.Sword
local meshes = script.Meshes
local KeyProvider = game:GetService("KeyframeSequenceProvider")
local debris = game:GetService("Debris")
local handler = {
plrAnims = {
["L"] = plr.R6_Slash1,
["LL"] = plr.R6_Slash2,
["LLL"] = plr.R6_Slash3
},
SwordAnims = {
["L"] = swrd.R6_Sword1,
["LL"] = swrd.R6_Sword2,
["LLL"] = swrd.R6_Sword3
},
SwordHitboxes = {
["L"] = CFrame.Angles(math.rad(45), 0, 0),
["LL"] = CFrame.Angles(0, 0, 0),
["LLL"] = CFrame.Angles(0, 0, 0)
}
}
function handler.getAnimation(Humanoid,SwordAnimationController, sequence)
local length = 0
local keysuquence = KeyProvider:GetKeyframeSequenceAsync(handler.plrAnims[sequence].AnimationId)
local keyframes = keysuquence:GetKeyframes()
for i=1, #keyframes do
local Time = keyframes[i].Time
if Time > length then
length = Time
end
end
return Humanoid.Animator:LoadAnimation(handler.plrAnims[sequence]), SwordAnimationController.Animator:LoadAnimation(handler.SwordAnims[sequence]), length
end
function handler.Attack(Player,character,humrp,length,sequence)
local folder = Instance.new("Folder")
folder.Name = "SwordCombat"
folder.Parent = workspace
debris:AddItem(folder, .25)
local hitbox = meshes.HitBox
hitbox.Size = Vector3.new(0.424, 5.018, 0.228)
hitbox.Transparency = 0
hitbox.CFrame = humrp.CFrame * CFrame.new(0,0,0) * handler.SwordHitboxes[sequence]
hitbox.Parent = folder
local weld1 = Instance.new("ManualWeld")
weld1.Name = "HitboxW"
weld1.Part0 = hitbox
weld1.Part1 = humrp
weld1.C0 = weld1.Part0.CFrame:ToObjectSpace(weld1.Part1.CFrame)
weld1.Parent = weld1.Part0
end
return handler