|
so if I wanted to say
local valuee = game.workspace
if valuee.value = 0 then the health of human would decrease 1 every second? |
|
|
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. |
|
|
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 |
|
|
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 |
|
|
Alright thanks for the help. Appreciate it. |
|
|
one problem it says
expected end to close got until.
something is write with
until val1 > 0 |
|
|
It is missing an end because there is an if then statement within the loop
The Legend of Heroes Sen no Kiseki |
|
|
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.
|
|
NotwalJoin Date: 2014-12-31 Post Count: 915 |
You need an end for that if statement |
|
|
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?
|
|
|
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) |
|
|
"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. |
|
|
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? |
|
|
"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. |
|
|
Player is not a valid member of players it says |
|
|
"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. |
|
|
if I wanna wait for character what would I put in the parenthesis
Character = game.Players:WaitForChild(""); |
|
|
The parentheses contain the name of the player.
You can utilize this to access the player's character. |
|
|
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. |
|
|
"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.
|
|
|
I added that in and it still says Character is not a valid member of players |
|
|
Could you show me the current version of your script? |
|
|
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
|
|
|
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". |
|
sublevelJoin Date: 2015-12-05 Post Count: 26 |
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); |
|