Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local hitmeplz = {"Arm1","Arm2","Chest","Face","Leg1","Leg2"}
- local player
- local tool = script.Parent.Parent
- local handle = tool:WaitForChild("Handle")
- local hole = tool:WaitForChild("Hole")
- local flash = hole.FlashGui
- local lastShot = tick()
- local equipped = false
- local reloading = false
- local configs = tool:WaitForChild("Configs")
- local remotes = tool:WaitForChild("Remotes")
- local ammo = configs:WaitForChild("Ammo")
- local reserveAmmo = configs:WaitForChild("ReserveAmmo")
- local magSize = configs:WaitForChild("MagSize")
- local damage = configs:WaitForChild("Damage")
- local fireRate = configs:WaitForChild("FireRate")
- local headMultiplier = configs:WaitForChild("HeadMultiplier")
- local range = configs:WaitForChild("Range")
- local reloadTime = configs:WaitForChild("ReloadTime")
- local canShootRemote = remotes:WaitForChild("CanShoot")
- local canReloadRemote = remotes:WaitForChild("CanReload")
- local reloadRemote = remotes:WaitForChild("Reload")
- local hitRemote = remotes:WaitForChild("Hit")
- local shootRemote = remotes:WaitForChild("Shoot")
- local emptySound = handle:WaitForChild("EmptySound")
- local reloadSound = handle:WaitForChild("ReloadSound")
- local shootSound = handle:WaitForChild("ShootSound")
- local headshotSound = handle:WaitForChild("HeadshotSound")
- local function canReload(plr)
- if ammo.Value < magSize.Value then
- if reserveAmmo.Value > 0 then
- if not reloading then
- if equipped then
- return true
- end
- end
- end
- end
- return false
- end
- local function reload(plr)
- if not canReload() then return end
- reloading = true
- script.Parent.Parent.Configs.Reload.Value = true
- reloadSound:Play()
- ammo.Value = "REL"
- if reserveAmmo.Value < 0 then
- ammo.Value = ammo.Value + reserveAmmo.Value
- reserveAmmo.Value = 0
- end
- wait(reloadTime.Value + .1)
- local needed = magSize.Value - ammo.Value
- reserveAmmo.Value = reserveAmmo.Value - needed
- ammo.Value = magSize.Value
- reloading = false
- script.Parent.Parent.Configs.Reload.Value = false
- end
- local function canShoot(plr, playSound)
- if math.abs(lastShot - tick()) > (60/fireRate.Value) then
- if not reloading then
- if equipped then
- if ammo.Value > 0 then
- return true
- else
- if playSound then
- emptySound:Play()
- end
- end
- end
- end
- end
- return false
- end
- local function shoot()
- local character = player.Character or player.CharacterAdded:Wait()
- local humanoid = character:WaitForChild("Humanoid")
- if humanoid.Health >= 0 then
- if not canShoot(player, true) then return end
- shootSound:Play()
- lastShot = tick()
- ammo.Value = ammo.Value - 1
- flash.Enabled = true
- script.Parent.Parent.Configs.Trace.Value = true
- wait(60/fireRate.Value)
- flash.Enabled = false
- script.Parent.Parent.Configs.Trace.Value = false
- end
- end
- local function hit(plr, part)
- if not canShoot() then return end
- if not part then return end
- local character = player.Character or player.CharacterAdded:Wait()
- local rootPart = character:WaitForChild("HumanoidRootPart")
- if rootPart then
- if (rootPart.CFrame.p - part.CFrame.p).magnitude <= range.Value then --//Check range
- local humanoid
- if part.Name == "Handle" then
- humanoid = part.Parent.Parent:FindFirstChild("Humanoid")
- else
- humanoid = part.Parent:FindFirstChild("Humanoid")
- end
- for i,v in pairs(hitmeplz) do
- if part.Parent.Name == v then
- humanoid = part.Parent.Parent:FindFirstChild("Humanoid")
- end
- end
- if humanoid and humanoid.Health > 0 then --//Do nothing if humanoid is dead
- local newDamage = damage.Value
- if part.Name == "Head" then
- newDamage = newDamage * headMultiplier.Value
- local soundCopy = headshotSound:Clone()
- soundCopy.Parent = part
- soundCopy:Play()
- end
- humanoid:TakeDamage(newDamage)
- end
- end
- end
- end
- local function equip()
- equipped = true
- player = game:GetService("Players"):GetPlayerFromCharacter(tool.Parent)
- end
- local function dequip()
- equipped = false
- end
- tool.Equipped:Connect(equip)
- tool.Unequipped:Connect(dequip)
- hitRemote.OnServerEvent:Connect(hit)
- shootRemote.OnServerEvent:Connect(shoot)
- reloadRemote.OnServerEvent:Connect(reload)
- canShootRemote.OnServerInvoke = canShoot
- canReloadRemote.OnServerInvoke = canReload
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement