Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I add spread to my raycast pistol?

Asked by
Axenori 124
5 years ago

I've asked this before and got an answer, but I didn't fully understand it. Code instead of an explanation would be greatly appreciated.

Local script:

01local BulletEvent = script.Parent:WaitForChild("BulletEvent")
02local debounce = false
03local v = 1
04script.Parent.Equipped:Connect(function(Mouse)
05 Mouse.Button1Down:Connect(function()
06    if script.Parent:FindFirstChild("AbleToShoot").Value == true then
07        local plr = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait()
08local chr = plr.Character or plr.CharacterAdded:Wait()
09local HP = chr:FindFirstChild("Humanoid").Health
10        if HP > 0 then
11    if debounce == false then
12        debounce = true
13    script.Parent.BulletEvent:FireServer(script.Parent.BE.CFrame.Position,Mouse.Hit.Position)
14    wait(0.5)
15    debounce = false
View all 24 lines...

Normal script

01script.Parent.BulletEvent.OnServerEvent:Connect(function(Player, FromP, ToP)
02 local RayCast = Ray.new(FromP,(ToP-FromP).unit*500)
03 local Part,Position,Normal = game.Workspace:FindPartOnRay(RayCast,Player.Character, false,true)
04 local Dist = (ToP-FromP).magnitude
05 if not Dist then Dist = 300 end
06 local Hole = game.ReplicatedStorage:FindFirstChild("GlockBulletHole"):Clone()
07if Part ~= nil then
08 Hole.Parent = Part.Parent
09 Hole.Position = ToP
10 Hole.CFrame = CFrame.new(Hole.Position, Hole.Position+Normal)
11 local Weld = Instance.new("Weld")
12 Weld.Part0 = Part
13 Weld.Part1 = Hole
14 Weld.C0 = Part.CFrame:Inverse()
15 Weld.C1 = Hole.CFrame:Inverse()
View all 51 lines...
0
Try adding random vector3 to the mouse position, like this Mouse.Hit.Position + Vector3.new(math.random(-2,2),math.random(-2,2),math.random(-2,2)) oilkas 364 — 5y
0
Tried it before, doesn't work Axenori 124 — 5y
0
oh oilkas 364 — 5y
0
did you do that where you are firing the event? oilkas 364 — 5y
0
no it works, just it places the bullet holes all wrong, some end up in the ground when firing at it, the event is in the tool Axenori 124 — 5y

Answer this question