Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Damage script for simple pistol that accesses a leaderstats with Points metric to score points on kills
- local gun = script.Parent
- local shootRe = gun:WaitForChild("ShootRe")
- local damage = gun.Configuration.Damage
- local bang = gun.Handle.Bang
- local assistTbl = {}
- function tagHumanoid(humanoid, player)
- for ply, v in pairs(assistTbl) do
- if ply.UserId ~= player.UserId then
- local Assist_Tag = Instance.new("ObjectValue")
- Assist_Tag.Name = "assist"
- Assist_Tag.Value = ply
- game.Debris:AddItem(Assist_Tag, 20)
- Assist_Tag.Parent = humanoid
- end
- end
- local Creator_Tag = Instance.new("ObjectValue")
- Creator_Tag.Name = "creator"
- Creator_Tag.Value = player
- game.Debris:AddItem(Creator_Tag, 20)
- Creator_Tag.Parent = humanoid
- end
- function untagHumanoid(humanoid)
- assistTbl = {}
- for i, v in pairs(humanoid:GetChildren()) do
- if v:IsA("ObjectValue") then
- if v.Name == "creator" or v.Name == "assist" then
- assistTbl[v.Value] = 1
- v:Destroy()
- end
- end
- end
- end
- local function scoreDamage(hum, player, damage)
- local damageDone = 0
- if hum.Health >= damage then
- damageDone = damage
- else
- damageDone = hum.Health
- end
- player.playerdata.Points.Value += damageDone
- end
- local function onShoot(player, target)
- bang:Play()
- if target and target.Parent then
- local hum = target.Parent:FindFirstChild("Humanoid")
- if hum then
- untagHumanoid(hum, player)
- tagHumanoid(hum, player)
- scoreDamage(hum, player, damage.Value)
- hum:TakeDamage(damage.Value)
- end
- end
- end
- shootRe.OnServerEvent:Connect(onShoot)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement