Well could it possibly be because of the first line
local raycast = workspace:Raycast(Tool.FirePos.Position,(Mouse.Hit.Position-Tool.FirePos.Position)+Vector3.new(Random.new():NextNumber(-Values.Spread.Value,Values.Spread.Value),Random.new():NextNumber(-Values.Spread.Value,Values.Spread.Value),Random.new():NextNumber(-Values.Spread.Value,Values.Spread.Value))*1.2) local result
it should instead be something like :
local raycast = workspace:Raycast(Tool.FirePos.Position, Mouse.Hit.Position - Tool.FirePos.Position)
local direction = (Mouse.Hit.Position - Tool.FirePos.Position).Unit
local spread = Vector3.new(Random.new():NextNumber(-Values.Spread.Value,Values.Spread.Value),Random.new():NextNumber(-Values.Spread.Value,Values.Spread.Value),Random.new():NextNumber(-Values.Spread.Value,Values.Spread.Value))
local raycast = workspace:Raycast(Tool.FirePos.Position, direction + spread * 1.2, RaycastParams.new())
local direction = (Mouse.Hit.Position - Tool.FirePos.Position).Unit
local spread = Vector3.new(Random.new():NextNumber(-Values.Spread.Value,Values.Spread.Value),Random.new():NextNumber(-Values.Spread.Value,Values.Spread.Value),Random.new():NextNumber(-Values.Spread.Value,Values.Spread.Value))
local raycast = workspace:Raycast(Tool.FirePos.Position, (direction + spread * 1.2).Unit)
Raycast Direction: Ensure that the direction vector is a unit vector (a vector of length 1). If the length of the direction vector is greater than 1, the raycast might not hit anything because it’s going beyond the intended target.
Raycast Length: The maximum length of a raycast is 15,000 studs. If the target is further away than this, the raycast will not hit it.
Raycast Parameters: The RaycastParams object can be used to selectively include or exclude certain BaseParts, ignore the Water material for Terrain, or use a collision group. Make sure that the target is not being excluded by the RaycastParams.
Target Properties: The target must be a BasePart or Terrain cell, and it must not be set to CanCollide = false. The Touched event will not fire for parts with CanCollide set to false.
Workspace Settings: The Workspace.FilteringEnabled property must be set to true for raycasting to work.
local spread = Vector3.new(Random.new():NextNumber(-Values.Spread.Value,Values.Spread.Value),Random.new():NextNumber(-Values.Spread.Value,Values.Spread.Value),Random.new():NextNumber(-Values.Spread.Value,Values.Spread.Value))
local raycast = workspace:Raycast(Tool.FirePos.Position,(Mouse.Hit.Position-Tool.FirePos.Position)*1.2)
This could be due to the script or the game just lagging. You could add a debounce to your script to reduce the lag with something like this local canFire = true
local spread = Vector3.new(new:NextNumber(-Values.Spread.Value,Values.Spread.Value),new:NextNumber(-Values.Spread.Value,Values.Spread.Value),new:NextNumber(-Values.Spread.Value,Values.Spread.Value))
local raycast = workspace:Raycast(Tool.FirePos.Position,(Mouse.Hit.Position-spread-Tool.FirePos.Position)*1.2)