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

Can someone please help me with making my gun automatic ? Thx!

Asked by 6 years ago

so, i made a rifle and i wanted to make it automatic. i scearched on google for it, yt, twitter, but i didnt find it. can you help me? here's teh script.

  local tool = script.Parent
local sound = tool:WaitForChild("Gunfire")
local player = game:GetService("Players").LocalPlayer

tool.Equipped:connect(function(mouse)
    print("Tool equipped!")

    mouse.Button1Down:connect(function()
        print("Mouse pressed!")
        local ray = Ray.new(tool.Handle.CFrame.p, (mouse.Hit.p - tool.Handle.CFrame.p).unit * 300)
        local part, position = workspace:FindPartOnRay(ray, player.Character, false, true)
        script.Parent.Shooting.Value = true

        local beam = Instance.new("Part", workspace)
        beam.BrickColor = BrickColor.new("Really red")
        beam.FormFactor = "Custom"
        beam.Material = "Neon"
        beam.Transparency = 0.5
        beam.Anchored = true
        beam.Locked = true
        beam.CanCollide = false

        local distance = (tool.Gun.CFrame.p - position).magnitude
        beam.Size = Vector3.new(0.3, 0.3, distance)
        beam.CFrame = CFrame.new(tool.Gun.CFrame.p, position) * CFrame.new(0, 0, -distance / 2)

        game:GetService("Debris"):AddItem(beam, 0.1)

        if script.Parent.Shooting.value then
                            script.Parent.Gunfire:Play()
                            script.Parent.Gun.PointLight.Enabled=true
                            wait(0.1)
                            script.Parent.Gun.PointLight.Enabled=false


        if part then
            local humanoid = part.Parent:FindFirstChild("Humanoid")

            if not humanoid then
                humanoid = part.Parent.Parent:FindFirstChild("Humanoid")
            end

            if humanoid then
                humanoid:TakeDamage(22)


                end

            end
        end
    end)
end)

Answer this question