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!):
local tool = script.Parent local player = game.Players.LocalPlayer local mouse = player:GetMouse() local hole = tool.Hole local flashgui = tool.Hole.Flash local range = tool.Configs.Range local equipped = false local reloading = false tool.Equipped:Connect(function() mouse.Button1Down:Connect(function() if not reloading then -- if tool.Remotes.CanShoot:InvokeServer() then not set up local ray = Ray.new(hole.CFrame.p, (mouse.hit.p - hole.CFrame.p).unit * range.Value) local touch, position = workspace:FindPartOnRay(ray, player.Character, false, true) local trace = Instance.new("Part") trace.Anchored = trace trace.CanCollide = false trace.Transparency = 0.5 trace.BrickColor = BrickColor.new("Black") trace.Material = Enum.Material.SmoothPlastic local distance = (hole.CFrame.p - position).magnitude trace.Size = Vector3.new(0, 0, distance) trace.CFrame = CFrame.new(hole.CFrame.p, position) * CFrame.new(0, 0, -distance/2) trace.Parent = workspace game:GetService("Debris"):AddItem(trace, 0.1) flashgui.Enabled = true wait(0.1) flashgui.Enabled = false -- end not set up end end) end)
Thanks in advance!
the last parameter of the ray call add another CFrame with Math.Random on the X and Y values