Need help with gun spread

Hi everyone, I’m new on the forum and I have a question about my game.
I want to make a spread for my weapon, but I don’t know how.
(give me please script and explain the some lines so that I can learn more)
LOCAL SCRIPT:

local tool = script.Parent
local handle = tool.Handle
local rate = tool:WaitForChild("Configure").Rate
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

tool.Activated:Connect(function()
local mouseHit = mouse.Hit.Position
tool.ShotEvent:FireServer(mouseHit,rate)
local bullet = game.ReplicatedStorage.Bullet:Clone()
bullet.Parent = workspace
bullet.CFrame = CFrame.new(handle.Position, mouseHit)
local Velocity = Instance.new("BodyVelocity", bullet)
Velocity.Velocity = bullet.CFrame.LookVector * 800
game:GetService("Debris"):AddItem(bullet, 15)
end)

SERVER SCRIPT:

local tool = script.Parent
local handle = tool.Handle

tool.ShotEvent.OnServerEvent:Connect(function(player, mouseHit, rate)
local shot = handle.FireSound:Clone()
shot.Parent = handle
shot:Play()
game:GetService("Debris"):AddItem(shot,4)
end)

I forgot to say that I create a bullet on the local server and when it touches, the bullet hole will appear on the server.

I think if you want to add spread, you have to add a randomized vector with the velocity

Velocity.Velocity = (bullet.CFrame.LookVector * 800) + Vector3.new(math.random(-10,10),math.random(-10,10),0)

You may have to change 10 to a different number if the spread is too weak. Basically right now you just have it so it’ll go where the bullet is looking, if you add a vector with it, it should act as spread

1 Like

Thank you for explaining now I understand.

1 Like