First Person Shooter (1-3)
LocalScript for Gun
local gun = script.Parent
local gun_sound = script.Parent.Handle["Gun Shot"]
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild('ShotEvent')
gun.Equipped:Connect(function(mouse)
mouse.Button1Down:Connect(function()
remoteEvent:FireServer(gun.Handle.Position, mouse.Hit.p)
gun_sound:Play()
end)
end)
ServerStorage (Name: Damage)
local bullet = script.Parent
local function player_check(otherPart)
local humanoid = otherPart.Parent:FindFirstChild('Humanoid')
if humanoid and humanoid.Parent.Name ~= bullet.Attacker.Value then
humanoid:TakeDamage(30)
local player = game.Players:FindFirstChild(humanoid.Parent.Name)
if player then
local tag = player:FindFirstChild('Killer')
if tag then
tag.Value = bullet.Attacker.Value
bullet:Destroy()
end
end
end
end
bullet.Touched:Connect(player_check)
ServerScriptService (Name: Leaderboard)
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
local killer = Instance.new('StringValue')
killer.Name = 'Killer'
killer.Parent = player
end
game.Players.PlayerAdded:Connect(onPlayerJoin)
--Death Tracker
game:GetService('Players').PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
character:WaitForChild("Humanoid").Died:Connect(function()
player.leaderstats.Deaths.Value = player.leaderstats.Deaths.Value + 1
local killerTag = game.Players:FindFirstChild(player.Killer.Value)
if killerTag then
killerTag.leaderstats.Kills.Value = killerTag.leaderstats.Kills.Value + 1
end
end)
end)
end)
ServerScriptService (Name: BulletCreate)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild('ShotEvent')
local ServerStorage = game:GetService('ServerStorage')
remoteEvent.OnServerEvent:Connect(function(player, gunPos, mosPos)
local bullet = Instance.new('Part')
bullet.Name = 'Bullet'
bullet.Parent = game.Workspace
bullet.Shape = Enum.PartType.Cylinder
bullet.Size = Vector3.new(.5,.25,.5)
bullet.BrickColor = BrickColor.new('Gold')
local damageScript = ServerStorage:FindFirstChild('Damage'):Clone()
damageScript.Parent = bullet
local attacker = Instance.new('StringValue')
attacker.Name = 'Attacker'
attacker.Parent = bullet
attacker.Value = player.Name
local speed = 500
bullet.CFrame = CFrame.new(gunPos, mosPos)
bullet.Velocity = bullet.CFrame.lookVector * speed
game:GetService("Debris"):AddItem(bullet, 2)
end)