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: How do I find players health?

Previous Thread :: Next Thread 
KingDoodleBob is not online. KingDoodleBob
Joined: 05 Aug 2009
Total Posts: 14092
01 Jan 2016 10:32 AM
so if I wanted to say
local valuee = game.workspace
if valuee.value = 0 then the health of human would decrease 1 every second?
Report Abuse
AnonyAnonymous is not online. AnonyAnonymous
Joined: 23 Jun 2013
Total Posts: 6332
01 Jan 2016 10:45 AM
The health of each player is a property of the "Humanoid" object, which is inside an individual's character.

The health of a given player's character is stored numerically; as a result, you would need to refer to the property with a scripting expression such as the following:

"game.Players.Player.Character.Humanoid.Health"

Afterwards, you could presumably loop a conditional statement to make a comparison of the individual's health and a specific value.
Report Abuse
KingDoodleBob is not online. KingDoodleBob
Joined: 05 Aug 2009
Total Posts: 14092
01 Jan 2016 11:17 AM
so would this be applicable?

local health = game.Players.Player.Character.Humanoid.Health
local val1 = game.StarterGui.Value

function one()
repeat wait (1)
if val1.Value = 0 then health -1
until val1.Value >0
Report Abuse
AnonyAnonymous is not online. AnonyAnonymous
Joined: 23 Jun 2013
Total Posts: 6332
01 Jan 2016 11:26 AM
Despite some syntactical errors, your expression is rather accurate, logically-speaking.

I would recommend that you refer directly to the Humanoid object, rather than the Health property itself.

local humanoid = game.Players.Player.Character.Humanoid
local val1 = game.StarterGui.Value

function one()

repeat wait (1)

if val1.Value == 0 then

humanoid.Health = humanoid.Health - 1;

until val1.Value > 0

end
Report Abuse
KingDoodleBob is not online. KingDoodleBob
Joined: 05 Aug 2009
Total Posts: 14092
01 Jan 2016 11:31 AM
Alright thanks for the help. Appreciate it.
Report Abuse
KingDoodleBob is not online. KingDoodleBob
Joined: 05 Aug 2009
Total Posts: 14092
01 Jan 2016 11:34 AM
one problem it says

expected end to close got until.

something is write with

until val1 > 0
Report Abuse
MahouReikon is not online. MahouReikon
Joined: 15 Feb 2014
Total Posts: 1359
01 Jan 2016 11:36 AM
It is missing an end because there is an if then statement within the loop


The Legend of Heroes Sen no Kiseki
Report Abuse
AnonyAnonymous is not online. AnonyAnonymous
Joined: 23 Jun 2013
Total Posts: 6332
01 Jan 2016 11:37 AM
Ah yes, it occurs to me that I did not entirely revise the syntactical-errors properly.

When you are utilizing functions/conditional statements, it is necessary to use the "end" keyword so that the interpreter will understand whether you are still within the range of the function/statement itself.

An example would be the following:

function A()

end

"end" merely informs the interpreter that you have completed the instructions for that given function.
Report Abuse
Notwal is not online. Notwal
Joined: 31 Dec 2014
Total Posts: 915
01 Jan 2016 11:37 AM
You need an end for that if statement
Report Abuse
KingDoodleBob is not online. KingDoodleBob
Joined: 05 Aug 2009
Total Posts: 14092
01 Jan 2016 11:39 AM
What I want this to do is if the val1.Value is = 0 then your health will drop 1 every second until that value is greater than 0.



so then where would I put until val1.Value > 0?
Report Abuse
KingDoodleBob is not online. KingDoodleBob
Joined: 05 Aug 2009
Total Posts: 14092
01 Jan 2016 11:41 AM
local humanoid = game.Players.Player.Character.Humanoid
local val1 = game.StarterGui.Value
function one()
repeat wait (1)
if val1.Value == 0 then
humanoid.Health = humanoid.Health - 1;
end
until val1.Value > 0



like this? I tried this but it doesn't work (I can already tell by where I put the until it is wrong but I don't know how to fix it)
Report Abuse
AnonyAnonymous is not online. AnonyAnonymous
Joined: 23 Jun 2013
Total Posts: 6332
01 Jan 2016 11:41 AM
"so then where would I put until val1.Value > 0?"

Ensure that this statement precedes any of the termination keywords or it will be interpreted separately.
Report Abuse
KingDoodleBob is not online. KingDoodleBob
Joined: 05 Aug 2009
Total Posts: 14092
01 Jan 2016 11:44 AM
take a look at the script I just posted but I got another question

I have it a local script in starter gui is that alright?
Report Abuse
AnonyAnonymous is not online. AnonyAnonymous
Joined: 23 Jun 2013
Total Posts: 6332
01 Jan 2016 11:48 AM
"local humanoid = game.Players.Player.Character.Humanoid
local val1 = game.StarterGui.Value
function one()
repeat wait (1)
if val1.Value == 0 then
humanoid.Health = humanoid.Health - 1;

end --This is the end for the conditional statement within the repeat loop;

until val1.Value > 0 --This is the condition for the repeat loop;

end --This is the end for the function containing the statements itself;
"

Also, given the client-sided nature of a LocalScript, I would recommend that you place this within a regular script.
Report Abuse
KingDoodleBob is not online. KingDoodleBob
Joined: 05 Aug 2009
Total Posts: 14092
01 Jan 2016 11:54 AM
Player is not a valid member of players it says
Report Abuse
AnonyAnonymous is not online. AnonyAnonymous
Joined: 23 Jun 2013
Total Posts: 6332
01 Jan 2016 12:00 PM
"Player is not a valid member of players it says"

The Lua expression that I provided was just an example.

"Player" refers solely to the name of the player that you would like to modify.

You may want to ensure that the player is in existence by using an expression such as the following:

Player = game.Players:WaitForChild("PlayerName");

Such an expression would wait for an object with the name of the player you are seeking to appear within the Players table. "Child" simply refers to the player.
Report Abuse
KingDoodleBob is not online. KingDoodleBob
Joined: 05 Aug 2009
Total Posts: 14092
01 Jan 2016 12:07 PM
if I wanna wait for character what would I put in the parenthesis


Character = game.Players:WaitForChild("");
Report Abuse
AnonyAnonymous is not online. AnonyAnonymous
Joined: 23 Jun 2013
Total Posts: 6332
01 Jan 2016 12:09 PM
The parentheses contain the name of the player.

You can utilize this to access the player's character.
Report Abuse
KingDoodleBob is not online. KingDoodleBob
Joined: 05 Aug 2009
Total Posts: 14092
01 Jan 2016 12:11 PM
I'm so confused now it says Character isn't a part of players.

sorry.. I'm not that advanced in scripting as you can tell.
Report Abuse
AnonyAnonymous is not online. AnonyAnonymous
Joined: 23 Jun 2013
Total Posts: 6332
01 Jan 2016 12:16 PM
"sorry.. I'm not that advanced in scripting as you can tell."

Actually, it is my fault for improperly analyzing your Lua expressions.

"game.Players:WaitForChild()" functions by waiting for any object with the specified name inside the parentheses to appear within the Players table.

"game.Players:WaitForChild().Character" will attempt to access the character of the given object(Assuming it is an actual player).

Here is an example:

"Character = game.Players:WaitForChild("Player1").Character;"

This line would wait for a child known as "Player1" to appear within the Players table, and attempt to access the character of Player1.

Inform me of any remaining confusion you may have.

Report Abuse
KingDoodleBob is not online. KingDoodleBob
Joined: 05 Aug 2009
Total Posts: 14092
01 Jan 2016 12:46 PM
I added that in and it still says Character is not a valid member of players
Report Abuse
AnonyAnonymous is not online. AnonyAnonymous
Joined: 23 Jun 2013
Total Posts: 6332
01 Jan 2016 12:49 PM
Could you show me the current version of your script?
Report Abuse
KingDoodleBob is not online. KingDoodleBob
Joined: 05 Aug 2009
Total Posts: 14092
01 Jan 2016 12:50 PM
local humanoid = game.Players.Character.Humanoid
local val1 = game.StarterGui.Value
Player = game.Players:WaitForChild("PlayerName");
Character = game.Players:WaitForChild("Player1").Character;
function one()
repeat wait (1)
if val1.Value == 0 then
humanoid.Health = humanoid.Health - 1;
end
until val1.Value > 0
end
Report Abuse
AnonyAnonymous is not online. AnonyAnonymous
Joined: 23 Jun 2013
Total Posts: 6332
01 Jan 2016 12:53 PM
Now I see the problem that you are having.

When I gave the "Player" and "Character" expressions, I was merely giving you them as an example.

You can solve your current problem by removing those lines and modifying the line for the humanoid variable to "humanoid = game.Players:WaitForChild("PlayerNameHere").Character.Humanoid".
Report Abuse
sublevel is not online. sublevel
Joined: 05 Dec 2015
Total Posts: 26
01 Jan 2016 01:21 PM
function FindPlayerHealth(Playername, DValue, SValue)
if (game.Workspace:FindFirstChild(Playername) ~= nil) then
while (DValue == 0) do
wait()
game.Workspace[Playername].Humanoid.Health = game.Workspace[Playername].Humanoid.Health - 1;
if (math.abs(game.Workspace[Playername].Humanoid.Health) <= math.abs(SValue)) then
break;
end;
end;
return game.Workspace[Playername].Humanoid.Health;
end;
end;

Health = FindPlayerHealth("Player1", 0, 10.00) -- If DValue is equal to 0 then decrement the health of the player until it reaches 10
print(Health);
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