Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Player = game.Players.LocalPlayer.Name
- local Gun = "AK-47" -- < -- Gun Name
- local Run = game:GetService("RunService")
- Gun = game.Players[Player].Character[Gun]
- local Mouse = game.Players.LocalPlayer:GetMouse()
- local Down = false
- local Sound = Gun.Handle.FireSound
- function CreateRay(Point_A, Point_B)
- local Ray = Ray.new(Point_A, (Point_B - Point_A).Unit * (2 ^ 31 - 1))
- local Part, Pos = workspace:FindPartOnRay(Ray, game.Players.LocalPlayer.Character)
- local Dist = (Point_A - Pos).Magnitude
- local CFrame = CFrame.new(Point_A, Pos) * CFrame.new(0, 0, -Dist / 2)
- return CFrame, Dist, Ray
- end
- function FireLaser(target)
- coroutine.resume(coroutine.create(function()
- local C, D, R = CreateRay(Gun.Muzzle.CFrame.p, target.CFrame.p)
- local Bullet = Instance.new("Part", Gun)
- Bullet.BrickColor = BrickColor.Yellow()
- Bullet.Material = "Neon"
- Bullet.Anchored = true
- Bullet.CanCollide = false
- Bullet.Size = Vector3.new(0.2, 0.2, D)
- Bullet.CFrame = C
- local bulletTable = {}
- table.insert(bulletTable, {
- Hit = target,
- Distance = D,
- Cframe = C,
- RayObject = R
- })
- game.ReplicatedStorage.ShootEvent:FireServer(bulletTable, Gun)
- local C = Sound:Clone()
- C.Parent = Gun
- C:Play()
- wait(0.05)
- Bullet:Remove()
- end))
- end
- Mouse.Button1Down:Connect(function()
- Down = true
- end)
- Mouse.Button1Up:Connect(function()
- Down = false
- end)
- while Run.Stepped:wait() do
- if Down == true then
- game.ReplicatedStorage.SoundEvent:FireServer(Sound, Gun)
- FireLaser(Mouse.Target)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement