How can i add spread to this ray casting weapon?
I can't find out how to add spread to this weapon. I searched around this forum, and i saw this post. https://scriptinghelpers.org/questions/83500/how-would-i-add-spread-to-a-raycasting-gun
I tried adding the answer to my current gun, but i can't find a way to use it in my gun.
My script(any parts in comments are not set up!):
01 | local tool = script.Parent |
02 | local player = game.Players.LocalPlayer |
03 | local mouse = player:GetMouse() |
05 | local flashgui = tool.Hole.Flash |
06 | local range = tool.Configs.Range |
08 | local reloading = false |
15 | tool.Equipped:Connect( function () |
18 | mouse.Button 1 Down:Connect( function () |
21 | local ray = Ray.new(hole.CFrame.p, (mouse.hit.p - hole.CFrame.p).unit * range.Value) |
22 | local touch, position = workspace:FindPartOnRay(ray, player.Character, false , true ) |
25 | local trace = Instance.new( "Part" ) |
26 | trace.Anchored = trace |
27 | trace.CanCollide = false |
28 | trace.Transparency = 0.5 |
29 | trace.BrickColor = BrickColor.new( "Black" ) |
30 | trace.Material = Enum.Material.SmoothPlastic |
32 | local distance = (hole.CFrame.p - position).magnitude |
33 | trace.Size = Vector 3. new( 0 , 0 , distance) |
34 | trace.CFrame = CFrame.new(hole.CFrame.p, position) * CFrame.new( 0 , 0 , -distance/ 2 ) |
35 | trace.Parent = workspace |
37 | game:GetService( "Debris" ):AddItem(trace, 0.1 ) |
39 | flashgui.Enabled = true |
42 | flashgui.Enabled = false |
Thanks in advance!