First Person Shooter 7-8

Sprint LocalScript (StarterPlayerScripts)

local userInput = game:GetService("UserInputService")

local players = game:GetService("Players")


local sprintSpeed = 30

local walkSpeed = 16


local player = players.LocalPlayer


local function beginSprint(input, gameProcessed)

if not gameProcessed then

if input.UserInputType == Enum.UserInputType.Keyboard then

local keycode = input.KeyCode

if keycode == Enum.KeyCode.LeftShift then

player.Character.Humanoid.WalkSpeed = sprintSpeed

end

end

end

end


local function endSprint(input, gameProcessed)

if not gameProcessed then

if input.UserInputType == Enum.UserInputType.Keyboard then

local keycode = input.KeyCode

if keycode == Enum.KeyCode.LeftShift then

player.Character.Humanoid.WalkSpeed = walkSpeed

end

end

end

end


userInput.InputBegan:Connect(beginSprint)

userInput.InputEnded:Connect(endSprint)

Arms LocalScript (StarterPlayerScripts)

local player = game.Players.LocalPlayer


local model = game.Workspace:WaitForChild(player.Name)


local rightLower = model:FindFirstChild('RightLowerArm')

local rightUpper = model:FindFirstChild('RightUpperArm')

local rightHand = model:FindFirstChild('RightHand')


game:GetService("RunService").RenderStepped:connect(function()

rightLower.LocalTransparencyModifier = 0

rightHand.LocalTransparencyModifier = 0

rightUpper.LocalTransparencyModifier = 0

end)

AmmoDrop Script(ServerStorage)

local ammo = script.Parent


local ReplicatedStorage = game:GetService('ReplicatedStorage')

local ammoEvent = ReplicatedStorage:WaitForChild('AmmoPickup')


local function ammo_pickup(otherPart)

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

local player = game.Players:FindFirstChild(otherPart.Parent.Name)

if humanoid and player then

local gun = humanoid.Parent:FindFirstChildWhichIsA('Tool')

if gun then

ammoEvent:FireClient(player)

ammo:Destroy()

end

end

end



ammo.Touched:Connect(ammo_pickup)


Leaderboard Script (ServerScriptService)

local function onPlayerJoin(player)

local leaderstats = Instance.new("Folder")

leaderstats.Name = 'leaderstats'

leaderstats.Parent = player

local kills = Instance.new("IntValue")

kills.Value = 0

kills.Name = 'Kills'

kills.Parent = leaderstats

local deaths = Instance.new('IntValue')

deaths.Value = 0

deaths.Name = 'Deaths'

deaths.Parent = leaderstats

end


game.Players.PlayerAdded:Connect(onPlayerJoin)


local function drop_ammo(death_pos)

wait(1)

local ammo = Instance.new('Part')

ammo.Parent = game.Workspace

ammo.Position = death_pos

ammo.Name = 'Ammo Drop'

local ammoScript = game.ServerStorage:FindFirstChild('AmmoDrop'):Clone()

ammoScript.Parent = ammo

end



--Death Tracker


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

player.CharacterAdded:Connect(function(character)

character:WaitForChild("Humanoid").Died:Connect(function()

print(character.HumanoidRootPart.Position)

drop_ammo(character.HumanoidRootPart.Position)

player.leaderstats.Deaths.Value = player.leaderstats.Deaths.Value + 1

local killer = game.Players:FindFirstChild(player.Killer.Value)

killer.leaderstats.Kills.Value = killer.leaderstats.Kills.Value + 1

end)

end)

end)

Gun LocalScript

--Object and Sound Variables

local gun = script.Parent

local gun_sound = gun.Handle["Gun Shot"]

local empty_sound = gun.Handle.clip_empty

local reload_sound = gun.Handle.Reload

local player = game.Players.LocalPlayer

local clipSize = gun:WaitForChild('Ammo').Value

local ammo = gun:WaitForChild('Ammo')



--UserInputService Setup

local userInput = game:GetService('UserInputService')



--Mouse Icon

local mouse = game.Players.LocalPlayer:GetMouse()


mouse.Icon = 'rbxassetid://117431027'


--Remote Event Setup


local ReplicatedStorage = game:GetService("ReplicatedStorage")

local remoteEvent = ReplicatedStorage:WaitForChild('ShotEvent')

local ammoEvent = ReplicatedStorage:WaitForChild('AmmoPickup')


-- Update Ammo


local function update_ammo()

player.PlayerGui.ScreenGui.Ammo.Text = 'Ammo: ' .. tostring(ammo.Value) .. ' / ' .. tostring(gun.MaxAmmo.Value)

end



--Checks if Mouse is clicked


gun.Equipped:Connect(function(mouse)

player.PlayerGui.ScreenGui.Ammo.Visible = true

update_ammo()

mouse.Button1Down:Connect(function()

if gun.Ammo.Value > 0 then

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

gun_sound:Play()

gun.Ammo.Value = gun.Ammo.Value - 1

else

empty_sound:Play()

end

end)

mouse.Button2Down:Connect(function()

local camera = game.Workspace.CurrentCamera

camera.FieldOfView = 40

end)

mouse.Button2Up:Connect(function()

local camera = game.Workspace.CurrentCamera

camera.FieldOfView = 70

end)

end)


-- Unequip gun


gun.Unequipped:Connect(function()

player.PlayerGui.ScreenGui.Ammo.Visible = false

end)



--Checks if the letter R is pressed to reload


userInput.InputBegan:Connect(function(input, gameProcessed)

if not gameProcessed then

if input.UserInputType == Enum.UserInputType.Keyboard then

local keycode = input.KeyCode

if keycode == Enum.KeyCode.R then

if gun.Ammo.Value < clipSize and gun.MaxAmmo.Value > 0 then

reload_sound:Play()

reload_sound.Ended:Wait()

if gun.MaxAmmo.Value - (clipSize - gun.Ammo.Value) >= 0 then

gun.MaxAmmo.Value = gun.MaxAmmo.Value - (clipSize - gun.Ammo.Value)

gun.Ammo.Value = gun.Ammo.Value + (clipSize - gun.Ammo.Value)

else

gun.Ammo.Value = gun.Ammo.Value + gun.MaxAmmo.Value

gun.MaxAmmo.Value = 0

update_ammo()

end

end

end

end

end

end)


-- Update ammo GUI



ammo.Changed:Connect(update_ammo)



ammoEvent.OnClientEvent:Connect(function()

gun.MaxAmmo.Value = gun.MaxAmmo.Value + 10

update_ammo()

end)