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
4 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:

local BulletEvent = script.Parent:WaitForChild("BulletEvent")
local debounce = false
local v = 1
script.Parent.Equipped:Connect(function(Mouse)
 Mouse.Button1Down:Connect(function()
    if script.Parent:FindFirstChild("AbleToShoot").Value == true then
        local plr = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait()
local chr = plr.Character or plr.CharacterAdded:Wait()
local HP = chr:FindFirstChild("Humanoid").Health
        if HP > 0 then
    if debounce == false then
        debounce = true
    script.Parent.BulletEvent:FireServer(script.Parent.BE.CFrame.Position,Mouse.Hit.Position)
    wait(0.5)
    debounce = false
    end
        elseif v == 1 then
            v = 0
wait(2)
v = 1
    end
    end
end)
    end)

Normal script


script.Parent.BulletEvent.OnServerEvent:Connect(function(Player, FromP, ToP) local RayCast = Ray.new(FromP,(ToP-FromP).unit*500) local Part,Position,Normal = game.Workspace:FindPartOnRay(RayCast,Player.Character, false,true) local Dist = (ToP-FromP).magnitude if not Dist then Dist = 300 end local Hole = game.ReplicatedStorage:FindFirstChild("GlockBulletHole"):Clone() if Part ~= nil then Hole.Parent = Part.Parent Hole.Position = ToP Hole.CFrame = CFrame.new(Hole.Position, Hole.Position+Normal) local Weld = Instance.new("Weld") Weld.Part0 = Part Weld.Part1 = Hole Weld.C0 = Part.CFrame:Inverse() Weld.C1 = Hole.CFrame:Inverse() Weld.Parent = Hole if Part and Part.Parent:FindFirstChild("Humanoid") ~= nil then Part.Parent.Humanoid:TakeDamage(30) Hole:FindFirstChild("Front").Texture = "rbxassetid://2078208894" Hole:FindFirstChild("Back").Texture = "rbxassetid://2078208894" else if Part.Parent.Parent:FindFirstChild("Humanoid") and Part ~= nil then Part.Parent.Parent:FindFirstChild("Humanoid"):TakeDamage(30) Hole:FindFirstChild("Front").Texture = "rbxassetid://2078208894" Hole:FindFirstChild("Back").Texture = "rbxassetid://2078208894" end end else local gunshot = Instance.new("Sound", script.Parent) gunshot.SoundId = "rbxassetid://356911785" gunshot:Play() script.Parent:FindFirstChild("Flare").MuzzleFlash.Enabled = true script.Parent:FindFirstChild("Flare").Smoke.Enabled = true wait(gunshot.TimeLength) gunshot:Destroy() end if Part then if Part.Parent ~= nil then if Part:FindFirstChild("IsGunHole") ~= nil then Hole:Destroy() else game.Debris:AddItem(Hole,10) end local gunshot = Instance.new("Sound", script.Parent) gunshot.SoundId = "rbxassetid://356911785" gunshot:Play() script.Parent:FindFirstChild("Flare").MuzzleFlash.Enabled = true script.Parent:FindFirstChild("Flare").Smoke.Enabled = true wait(gunshot.TimeLength) gunshot:Destroy() end end
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 — 4y
0
Tried it before, doesn't work Axenori 124 — 4y
0
oh oilkas 364 — 4y
0
did you do that where you are firing the event? oilkas 364 — 4y
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 — 4y

Answer this question