|
| 22 Jul 2015 11:09 AM |
How would I give every player within 10 studs of my torso 10 health?
I tried this..
local Humanoid = {} function TableContains(Table, Element) for _, Value in next, Table do if Value == Element then return true end end end
function Humanoid:GetNearestHumanoid(v3_Origin, int_Range, tbl_IgnoreDescendants) local Returned; for _, Child in next, workspace:GetChildren() do if not TableContains(tbl_IgnoreDescendants, Child) then if Child:IsA('Model') and Child:FindFirstChild('Head') then local Target; local Descendants = Child:GetChildren() local Alive = false for _, Descendant in next, Descendants do if Descendant:IsA('Humanoid') then Target = Descendant Alive = true; break end end if Alive then local Offset = Child.Head.Position - v3_Origin if Offset.magnitude < int_Range then Returned = Target int_Range = Offset.magnitude end end end end end return Returned end
local Closest = Humanoid:GetNearestHumanoid(plr.Character.Torso.Position, 100, {plr.Character})
but it only goes for ONE person, I want to give it to EVERYONE within range. |
|
|
| Report Abuse |
|
|
|
| 22 Jul 2015 11:13 AM |
a = false
while true do wait(1) if players is in x area if a = true end a = true localplayer.humanoid.health = local player.humanoid.health + 10 end end end
This is pseudo code. Obviously. But try it like this, I prefer this method of doing it
▲☭⎊▲Obama is a giant overlord space lizard▲⎊☭▲ |
|
|
| Report Abuse |
|
|
|
| 22 Jul 2015 11:14 AM |
local player = game.Players.LocalPlayer local healthBoost = 10 local healthBoostDistance = 10
function getCharacters(point, distance) local players = {} for i,v in pairs(game.Players:GetPlayers()) do if v ~= player and v.Character and v.Character.Parent and v:DistanceFromCharacter(point) <= distance then players[#players + 1] = v end end return players end
local players = getCharacters(player.Character.PrimaryPart, healthBoostDistance) for i,v in pairs(players) do local humanoid = v.Character:FindFirstChild("Humanoid") if humanoid then humanoid.Health = humanoid.Health + healthBoost end end |
|
|
| Report Abuse |
|
|
|
| 22 Jul 2015 11:25 AM |
@Above, I got an error.
Unable to cast Instance to Vector3
17:24:54.936 - Script 'Players.Player4.Backpack.LocalScript', Line 69 - global getCharacters 17:24:54.936 - Script 'Players.Player4.Backpack.LocalScript', Line 76 17:24:54.937 - Stack End |
|
|
| Report Abuse |
|
|
|
| 22 Jul 2015 11:29 AM |
local player = game.Players.LocalPlayer local healthBoost = 10 local healthBoostDistance = 10
function getCharacters(point, distance) local players = {} for i,v in pairs(game.Players:GetPlayers()) do if v ~= player and v.Character and v.Character.Parent and v:DistanceFromCharacter(point) <= distance then players[#players + 1] = v end end return players end
local players = getCharacters(player.Character.PrimaryPart.Position, healthBoostDistance) for i,v in pairs(players) do local humanoid = v.Character:FindFirstChild("Humanoid") if humanoid then humanoid.Health = humanoid.Health + healthBoost end end |
|
|
| Report Abuse |
|
|
|
| 22 Jul 2015 12:25 PM |
| Nothing happens now, it just casts and finishes |
|
|
| Report Abuse |
|
|