I’m trying to make a sword and I’m working on the pullout portion of it but it’s not working. Whenever I try to equip it, it falls through the floor.
The error I get is “ServerScriptService.SwordCombat:25: invalid argument #2 (Vector3 expected, got nil)”
I have 2 scripts both called SwordCombat. One is a local script in StarterPack and the other one is a normal script in ServerScriptService.
This is the normal script.
local rp = game:GetService("ReplicatedStorage")
local Sword = rp:WaitForChild("Sword")
local cframes = {
["RightArm"] = CFrame.new(0,-1,0),
["RightHand"] = CFrame.new(0,0,0)
}
Sword.OnServerEvent:Connect(function(Player,isEquipped)
local Character = Player.Character
local Humanoid = Character.Humanoid
if isEquipped then
--Equipping the Sword
local Katana = Character:FindFirstChild("Katana")
if Katana then
local SideWeld = Katana.PrimaryPart:FindFirstChild("Sideweld")
if SideWeld then
SideWeld:Destroy()
if Humanoid.RigType == Enum.HumanoidRigType.R15 then
Katana:SetPrimaryPartCFrame(Character:WaitForChild("RightHand").CFrame*cframes["RightHand"])
elseif Humanoid.RigType == Enum.HumanoidRigType.R6 then
Katana:SetPrimaryPartCFrame(Character:WaitForChild("Right Arm").CFrame * cframes["Right Arm"])
end
local HandWeld = Instance.new("ManualWeld")
HandWeld.Part0 = Katana.PrimaryPart
if Humanoid.RigType == Enum.HumanoidRigType.R15 then
HandWeld.Part1 = Character:WaitForChild("RightHand")
elseif Humanoid.RigType == Enum.HumanoidRigType.R6 then
HandWeld.Part1 = Character:WaitForChild("Right Arm")
end
HandWeld.C0 = HandWeld.Part0.CFrame:ToObjectSpace(HandWeld.Part1.CFrame) * CFrame.Angles(0,math.rad(180),0)
HandWeld.Parent = HandWeld.Part0
end
end
elseif not isEquipped then
--Unequipping the Sword
end
end)
This is the local script
local rp = game:GetService("ReplicatedStorage")
local Sword = rp:WaitForChild("Sword")
local UIS = game:GetService("UserInputService")
local isEquipped = false
local debounce = false
local cd = 1
UIS.InputBegan:Connect(function(input,isTyping)
if not isTyping then
if input.KeyCode == Enum.KeyCode.E then
if not isEquipped then
isEquipped = true
Sword:FireServer(isEquipped)
elseif isEquipped and not debounce then
debounce = true
isEquipped = false
Sword:FireServer(isEquipped)
end
end
end
end)
Sword.OnClientEvent:Connect(function()
wait(cd)
debounce = false
end)