Advertisement
SimTek

Damage

May 11th, 2024
895
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.58 KB | Gaming | 0 0
  1. -- Damage script for simple pistol that accesses a leaderstats with Points metric to score points on kills
  2. local gun = script.Parent
  3. local shootRe = gun:WaitForChild("ShootRe")
  4. local damage = gun.Configuration.Damage
  5. local bang = gun.Handle.Bang
  6. local assistTbl = {}
  7.  
  8. function tagHumanoid(humanoid, player)
  9.     for ply, v in pairs(assistTbl) do
  10.         if ply.UserId ~= player.UserId then
  11.             local Assist_Tag = Instance.new("ObjectValue")
  12.             Assist_Tag.Name = "assist"
  13.             Assist_Tag.Value = ply
  14.             game.Debris:AddItem(Assist_Tag, 20)
  15.             Assist_Tag.Parent = humanoid  
  16.         end
  17.     end
  18.    
  19.     local Creator_Tag = Instance.new("ObjectValue")
  20.     Creator_Tag.Name = "creator"
  21.     Creator_Tag.Value = player
  22.     game.Debris:AddItem(Creator_Tag, 20)
  23.     Creator_Tag.Parent = humanoid
  24. end
  25.  
  26. function untagHumanoid(humanoid)
  27.     assistTbl = {}
  28.     for i, v in pairs(humanoid:GetChildren()) do
  29.         if v:IsA("ObjectValue") then
  30.             if v.Name == "creator" or v.Name == "assist" then
  31.                 assistTbl[v.Value] = 1
  32.                 v:Destroy()
  33.             end        
  34.         end
  35.     end
  36. end
  37.  
  38. local function scoreDamage(hum, player, damage)
  39.     local damageDone = 0
  40.     if hum.Health >= damage then
  41.         damageDone = damage
  42.     else
  43.         damageDone = hum.Health    
  44.     end
  45.     player.playerdata.Points.Value += damageDone
  46. end
  47.  
  48.  
  49. local function onShoot(player, target)
  50.     bang:Play()
  51.     if target and target.Parent then
  52.         local hum = target.Parent:FindFirstChild("Humanoid")
  53.         if hum then
  54.             untagHumanoid(hum, player)
  55.             tagHumanoid(hum, player)
  56.             scoreDamage(hum, player, damage.Value)
  57.             hum:TakeDamage(damage.Value)
  58.         end
  59.     end
  60. end
  61.  
  62. shootRe.OnServerEvent:Connect(onShoot)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement