Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

Why won't this script that i put in a health GUI sense that the health is lower than 99.9?

Asked by 10 years ago
local model = game.ServerStorage.Health:Clone()
local PlayerHealth = script.Parent.Parent.Parent.Parent.Character.Humanoid.Health 
if PlayerHealth <= 99.9 then
    wait()
    print("Rawr")
    wait(5)
    model.Parent = script.Parent.Parent.Parent.Parent.Character
end

1 answer

Log in to vote
1
Answered by 10 years ago

Sorry if I did not give a good explanation, rough week :(

Your problem is line 2; You only saved the Health of the Humanoid type instance, which is saving the Humanoid's Health when first executing, so it is comparing a saved 'Number' value to number type 99.9. Just remove .Health from there, and switch it to line 3, also, when you run this code, 'Humanoid' may not be existant at the time when the code has executed, thus may cause an error, let's use the WaitForChild Method for the code aswell; the WaitForChild Method will repeat waiting until the Child with the matching name is existant within the Parent, and will return the Child [Parent:WaitForChild(Child)]. Let's fix up your code;

local model = game.ServerStorage:WaitForChild("Health"):Clone() --This will repeat waiting until 'Health' is existant within 'ServerStorage', and will Clone it when existant, also will return the Cloned 'Health'; 'model' is now specified for the Cloned 'Health
local PlayerHealth = script.Parent.Parent.Parent.Parent.Character:WaitForChild("Humanoid") --This will repeat waiting until 'Humanoid' is existant within 'Character', and will return 'Humanoid' when existant; The 'Humanoid' within the Character is now specified as 'PlayerHealth'
if PlayerHealth.Health  <= 99.9 then --Checks, and compares the 'Humanoid''s current Health to '99.9', and if the Health is less than or equal to 99.9, then it'll run the following code; an 'if' statement checks the conditions for certain codes
print("Rawr") --Prints in the Output 'Rawr'
wait(5) --Waits 5 seconds before going on
model.Parent = script.Parent.Parent.Parent.Parent.Character --Sets the Child 'model''s Parent to the Player's Character
end --This ends the code for the 'if' statement

What the WaitForChild Method basically does is; it will repeat waiting until the first Argument finds a Child with the same 'Name' as the Argument; will repeat waiting until the Child with the matching Name is existant within the Parent

What the if then end Statement basically does is; it will check the requirements, or conditions, for a clock of code, here's an example of what I mean;

local Identifier = true --'Identifier' is set as 'true'; The identifier 'Identifier' is specified as 'true'
if Identifier then --The 'if' statement is checking if 'Identifier' is 'true', or not
print("Indentifier is set to true! :D") --This will print in the Output if so :D
end --This ends the code block for the 'if' statement

local Identifier2 = Instance.new("Part",game.Workspace) --Surprised yet?; 'Identifier2' is now identifying a new Instance 'Part'; 'Instance.new' will create, or spawn, a new Instance-type object
if Identifier2 then --Will check if 'Identifier2' is existant or not; Surprised you can do this with 'Part''s aswell? :)
print("Yay! Part exists! :D") --Will print this if 'Identifier2' is existant as a result! :D Surprised? :)
end --This ends the code block for the 'if' statement

Again, I am sorry if I did not give a good explanation, rough week. :( Hope this helped!

Ad

Answer this question