ive most likely asked this question before a long time ago but i keep coming back to this segment of code because it works to well
can someone explain what this part of the code does?, im lost trying to understand how some of it works
local Rv = MPos.Direction * 300
local Ray1 = workspace:Raycast(MPos.Origin, (Rv * Distance), Params)
local HitPos = if Ray1 then Ray1.Position else (MPos.Origin + Rv)
local AimAt = (HitPos - FirePoint.WorldPosition)
local BulletRay = workspace:Raycast(FirePoint.WorldPosition, AimAt * 2, Params)
local ThingHit = if BulletRay then BulletRay.Instance else nil
local PosHit = if BulletRay then BulletRay.Position else HitPos
full code
repeat task.wait() until game:IsLoaded() and script.Parent:FindFirstChild("Remotes")
-- Variables
local Player = game:GetService('Players').LocalPlayer
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local Ts = game:GetService("TweenService")
local Debris = game:GetService("Debris")
local Tool = script.Parent
local RemotesFolder = Tool.Remotes
local RSRemotesFolder = game.ReplicatedStorage.Remotes
local Mesh = Tool.GlockMesh
local Handle = Tool.Handle
local BulletPoint = Mesh.BulletPoint
local CTS = RemotesFolder.ClientToServer
local ClientBullet = RSRemotesFolder.ClientBullet
local BulletFolder = game.ReplicatedStorage.Bullets
local FirePoint = Tool.GlockMesh.BulletPoint
local BulletCoroutine
local RBullet
local Params = RaycastParams.new()
Params.FilterDescendantsInstances = {}
Params.FilterType = Enum.RaycastFilterType.Blacklist
-- Tool Data --
local IsAutomatic = true
local LastShotTime = os.clock()
local FireRate = 0.1
local MagAmmo = Tool.Data.MagAmmoNum
local IsHeldDown = false
local Distance = 500
local Bullet = game.ReplicatedStorage.Bullets.NormalBullet
-- --
-- Functions --
local function FireClientBullet(MPos)
local DebugPart1 = workspace.DebugPart1
local DebugPart2 = workspace.DebugPart2
-- The Part i dont understand well --
local Rv = MPos.Direction * 300
local Ray1 = workspace:Raycast(MPos.Origin, (Rv * Distance), Params)
local HitPos = if Ray1 then Ray1.Position else (MPos.Origin + Rv)
local AimAt = (HitPos - FirePoint.WorldPosition)
local BulletRay = workspace:Raycast(FirePoint.WorldPosition, AimAt * 2, Params)
local ThingHit = if BulletRay then BulletRay.Instance else nil
local PosHit = if BulletRay then BulletRay.Position else HitPos
-- --
local BClone = Bullet:Clone()
BClone.Size = Vector3.new(.2, .2, (FirePoint.WorldPosition - HitPos).Magnitude)
BClone.CFrame = CFrame.new(FirePoint.WorldPosition:Lerp(HitPos, .5), HitPos)
BClone.Parent = workspace
Ts:Create(BClone, TweenInfo.new(.3, Enum.EasingStyle.Quad), {Transparency = 1}):Play()
Debris:AddItem(BClone, .4)
end
local function Shoot()
local Mouse = UserInputService:GetMouseLocation()
local MousePosition = workspace.CurrentCamera:ViewportPointToRay(Mouse.X, Mouse.Y)
local DirectTime = os.clock()
CTS:FireServer("Fire")
FireClientBullet(MousePosition)
end
-- Main
Tool.Activated:Connect(Shoot)