Argument 2 Missing or Nil

Hey, I made a gun script (Very unfinished) for my fighting game, Now this is not entirely a script made by me, I only modified some parts, this script came from a youtube channel called “B Ricey”, I can’t make those by myself because I’m a stupid idiot, soo anyways the error was at line 28 (Server Script), I supposedly made a 2 different type of script: Client inside of the Tool itself and Server inside of ServerScriptService, here’s the script

Client

local Tool = script.Parent

local FirePoint = Tool:WaitForChild("Firepoint")

print(FirePoint)

print(FirePoint.Parent)

local Player = game.Players.LocalPlayer

local Mouse = Player:GetMouse()

local Config = Tool.Config

local Equip = Config.Animations.Equip

local Reload = Config.Animations.Reload

local Shoot = Config.Animations.Shoot

local FireEvent = game.ReplicatedStorage.Tools.GunsEvent.Fire

local BulletTrailFolder = workspace.BulletTrail

Mouse.TargetFilter = BulletTrailFolder

Tool.Activated:Connect(function()

local MousePosition = Mouse.Hit.Position

local FirePointPosition = FirePoint.Position

local Damage = 20

local MaxDamage = 35

FireEvent:FireServer(MousePosition, FirePointPosition, Damage, MaxDamage)

end)

Server

local FireEvent = game.ReplicatedStorage.Tools.GunsEvent.Fire
local BulletsFolder = workspace.BulletTrail
local Debris = game:GetService("Debris")

local GlobalRange = 500

local function CreateBeam(FirePoint, Direction)
	local MidPoint = FirePoint + Direction/2
	
	local Bullet = Instance.new("Part")
	Bullet.Parent = BulletsFolder
	Bullet.Anchored = true
	Bullet.CanCollide = false
	
	Bullet.Material = Enum.Material.Neon
	Bullet.Transparency = 0.5
	Bullet.BrickColor = BrickColor.new("Daisy orange")
	
	Bullet.CFrame = CFrame.new(MidPoint, FirePoint)
	Bullet.Size = Vector3.new(0.1, 0.1, Direction.Magnitude)
	
	Debris:AddItem(Bullet, .5)                                                                                          
end

FireEvent.OnServerEvent:Connect(function(Player, MousePosition, FirePointPosition, Damage, MaxDamage)
	local Direction = (MousePosition - FirePointPosition).Unit * GlobalRange
	
	local Result = workspace:Raycast(FirePointPosition)
	
	if Result then
		local Character = Result.Instance.Parent
		local Humanoid = Character:FindFirstChild("Humanoid")
		
		local PlayerHumanoid = Player.Humanoid
		
		Player:FindFirstChild("SniperBamboo").Config.Sounds.Shoot:Play()
		local ShootTrack = PlayerHumanoid.Animator:LoadAnimation(Player:FindFirstChild("SniperBamboo").Config.Animations.Shoot)
		ShootTrack:Play()
		
		if Humanoid and Humanoid ~= Player.Character.Humanoid then
			Humanoid:TakeDamage(Damage)
		elseif Character.Head and Character.Head ~= Player.Character.Head then
			Humanoid:TakeDamage(MaxDamage)
		end
	end
	
	CreateBeam(FirePointPosition, Direction)
end)
1 Like

Raycast requires at least 2 arguments and 1 more optional argument which are : Origin,Direction,RaycastParams (Optional)
so you must do

local Result = workspace:Raycast(FirePointPosition,Direction) -- you can make the Params and add it if you want.
local Result = workspace:Raycast(FirePointPosition)

There must be a second argument (rayDirection)