I'm working on a gun script, and when I click, the output says "Argument 2 missing or nil", and clicking on it brings me to line 21. Here's the script:
-- Variables
local UserInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local tool = script.Parent
local equipped = false
-- Raycasting Function
local function semiFire()
local camera = workspace.CurrentCamera
local semiParams = RaycastParams.new()
semiParams.FilterDescendantsInstances = {}
semiParams.FilterType = Enum.RaycastFilterType.Blacklist
local function semiResult(x, y)
local unitRay = camera:ScreenPointToRay(x, y)
return workspace:Raycast(unitRay.Origin, unitRay.Direction * 500, semiParams)
end
local semiResultV = semiResult()
if semiResultV then
local hitPart = semiResultV.Instance
local humanoid = hitPart.Parent:FindFirstChild("Humanoid")
if not humanoid then
local humanoid = hitPart.Parent.Parent:FindFirstChild("Humanoid")
end
if not humanoid then end
if humanoid then
print("THERES A HUMANOID POGGERS WOWOWOWOWOW")
end
end
end
-- Equip / Unequip
tool.Equipped:Connect(function(mouse)
equipped = true
end)
tool.Unequipped:Connect(function(mouse)
equipped = false
end)
-- Firing
UserInputService.InputBegan:Connect(function(input)
if equipped == true then
if input.UserInputType == Enum.UserInputType.MouseButton1 then
semiFire()
end
end
end)
UserInputService.InputEnded:Connect(function(input)
if equipped == true then
if input.UserInputType == Enum.UserInputType.MouseButton1 then
end
end
end)
Any help is much appreciated.
