Shotgun

Local Script for Gun

local gun = script.Parent

local gun_shot = gun.Handle['Gun Shot']


local ReplicatedStorage = game:GetService('ReplicatedStorage')

local remoteEvent = ReplicatedStorage:WaitForChild('ShotEvent')


local shooting = false

local equipped = false


local player = game.Players.LocalPlayer

local mouse = player:GetMouse()


local mouseConnection


gun.Equipped:Connect(function()

equipped = true

mouse.Icon = 'rbxassetid://117431027'

mouseConnection = mouse.Button1Down:Connect(function()

shooting = true

while shooting and equipped do

remoteEvent:FireServer(gun.Handle.Position, gun.Handle.Orientation, mouse.Hit.p)

gun_shot:Play()

mouse.Button1Up:Connect(function()

shooting = false

end)

wait(0.1)

end

end)

end)


gun.Unequipped:Connect(function()

equipped = false

mouseConnection:Disconnect()

end)


Script (ServerScriptService)

local ReplicatedStorage = game:GetService('ReplicatedStorage')

local remoteEvent = ReplicatedStorage:WaitForChild('ShotEvent')


local damage_amount = 25


local pellets = 5 --how many bullets shoot

local spread = 3 --how far apart they shoot

local range = 0.5 --how long before deleted



remoteEvent.OnServerEvent:Connect(function(player, gunPos, gunOr, mosPos)

for i = 0, pellets do

local bullet = Instance.new('Part')

bullet.Name = 'Bullet'

bullet.Parent = game.Workspace

bullet.Shape = Enum.PartType.Ball

bullet.Size = Vector3.new(0.1, 0.1, 0.1)

bullet.BrickColor = BrickColor.new('Lime green')

local spread = Vector3.new(math.random(1,spread),math.random(1,spread),math.random(1,spread))

local speed = 250

bullet.CFrame = CFrame.new(gunPos + spread, mosPos)

bullet.Velocity = bullet.CFrame.lookVector * speed


bullet.Touched:Connect(function(otherPart)

local humanoid = otherPart.Parent:FindFirstChild('Humanoid')

if humanoid and humanoid.Parent.Name ~= player.Name then

if humanoid.Health > 0 and humanoid.Health - damage_amount <= 0 then

player.leaderstats.Kills.Value += 1

end

humanoid:TakeDamage(damage_amount)

bullet:Destroy()

end

end)

game:GetService('Debris'):AddItem(bullet, range)

end

end)

Script (ServerScriptService)

game.Players.PlayerAdded:Connect(function(player)

local leaderstats = Instance.new("Folder")

leaderstats.Name = "leaderstats"

leaderstats.Parent = player

local kills = Instance.new("IntValue")

kills.Name = "Kills"

kills.Parent = leaderstats

end)