generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: If within 10 studs give 10 health

Previous Thread :: Next Thread 
CardsOfFate is not online. CardsOfFate
Joined: 08 Jul 2014
Total Posts: 761
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
WolfgangVonPrinz is not online. WolfgangVonPrinz
Joined: 24 Oct 2013
Total Posts: 4656
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
nQqzRYVpIKA5jLP is not online. nQqzRYVpIKA5jLP
Joined: 05 Mar 2015
Total Posts: 4135
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
CardsOfFate is not online. CardsOfFate
Joined: 08 Jul 2014
Total Posts: 761
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
nQqzRYVpIKA5jLP is not online. nQqzRYVpIKA5jLP
Joined: 05 Mar 2015
Total Posts: 4135
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
CardsOfFate is not online. CardsOfFate
Joined: 08 Jul 2014
Total Posts: 761
22 Jul 2015 12:25 PM
Nothing happens now, it just casts and finishes
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image