|
| 22 Jun 2015 06:28 PM |
Hello I am trying to make a game with little knowledge of Lua. That's gonna be how I learn hopefully.
I've got a game core that will end the game once its humanoid reaches 0. If it goes to 200 or below, smoke will be enabled. That's the problem though.
Here is a shorter example of my script:
bluecore = game.Workspace.BlueCore bcore = bluecore.Head bhp = bluecore.Humanoid.Health smoke = bcore.Smoke
while bhp <= 200 do smoke.Enabled = true wait() end
Now, when I test the script out I go into game and I lower the humanoid's HP (via button) to 200. Nothing happens. Now if I were to select this script, hit disable and then enable it again the smoke is enabled. So the script isn't actively waiting for the humanoid's HP to get to this level. How can I get it to do that? So the script will automatically do it once the HP reaches 200 or below, so I wouldn't have to refresh the script.
|
|
|
| Report Abuse |
|
|
|
| 22 Jun 2015 06:29 PM |
It also doesn't work with the if..then either. Here was my first script (The ENTIRE thing)
local core = script.Parent.Head local chp = script.Parent.Humanoid.Health local message1 = script.Configuration.Message1.Value local message2 = script.Configuration.Message2.Value local message3 = script.Configuration.Message3.Value local GRAVITY_ACCELERATION = script.Configuration.LauSpeed.Value local dettime = script.Configuration.DetTime.Value
if chp <=200 then -- Low HP, Smoke core.Smoke.Enabled = true msg = Instance.new("Hint") msg.Text = (message1) msg.Parent = game.Workspace wait(3) msg:Remove() end
if chp <=100 then -- Low HP, Smoke + Fire core.Smoke.Enabled = true msg = Instance.new("Hint") msg.Text = (message2) msg.Parent = game.Workspace wait(3) msg:Remove() end
if chp == 0 then -- 0 HP, Explosion core.Anchored = false msg1 = Instance.new("Hint") msg1.Text = (message3) msg1.Parent = game.Workspace script.Parent.Sound2:Play() local bodyForce = Instance.new('BodyForce', core) bodyForce.Name = 'Antigravity' bodyForce.force = Vector3.new(0, core:GetMass() * GRAVITY_ACCELERATION, 0) wait(dettime) explosion = Instance.new("Explosion") --original explosion.BlastPressure = 100 explosion.BlastRadius = 100 explosion.Parent = game.Workspace explosion.Position = core.Position script.Parent.Sound:Play() core:Destroy() msg1:Destroy() end
|
|
|
| Report Abuse |
|
|
| |
|
| |
|
|
| 22 Jun 2015 08:49 PM |
Try this: bluecore = game.Workspace.bluecore bcore = game.Workspace.bluecore.head bhp = game.Workspace.bluecore.Humaniod.Health smoke = game.Workspace.bluecore.Smoke |
|
|
| Report Abuse |
|
|
| |
|
gunter5
|
  |
| Joined: 15 Mar 2011 |
| Total Posts: 737 |
|
|
| 22 Jun 2015 09:47 PM |
ok it may be a typo error.
bluecore = game.Workspace.BlueCore -- you see here bluecore is BlueCore bcore = bluecore.Head -- that means bluecore.Head needs to be BlueCore.Head bhp = bluecore.Humanoid.Health -- same here BlueCore.Humanoid.Health smoke = bcore.Smoke -- this is fine
|
|
|
| Report Abuse |
|
|
| |
|
|
| 22 Jun 2015 11:12 PM |
Try this:
local bluecore = game.Workspace:WaitForChild("BlueCore")--Always use local and WaitForChild. local bcore = bluecore:WaitForChild("Head") local bhp = bluecore:WaitForChild("Humanoid")--Don't do the properties of an object, just the object. local smoke = bcore:WaitForChild("Smoke")
bhp.Changed:connect(function() --Use the changed event, not a while loop. if bhp.Health <200 then smoke.Enabled = true end
u sicko! |
|
|
| Report Abuse |
|
|
|
| 23 Jun 2015 12:09 AM |
Thank you very much! I took what you did but then used the HealthChanged event because you said "Use the changed event, not a while loop.", which gave me the reason to find healthchanged. Here is what I ended up with: (mind the missing variables)
function smoke() if chp.Health <= 200 then core.Smoke.Enabled = true else print("hi") end end chp.HealthChanged:connect(smoke)
THANK YOU I HAVE HAD THIS PROBLEM FOR A LONG TIME!! |
|
|
| Report Abuse |
|
|
|
| 23 Jun 2015 12:11 AM |
| But is there anything I can replace the print("hi") so it won't constantly have to do that during a game? Wouldn't it cause lag? If not then it's not an issue. |
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
| |
|
gunter5
|
  |
| Joined: 15 Mar 2011 |
| Total Posts: 737 |
|
|
| 23 Jun 2015 03:16 PM |
do this if you dont understand what time said this is the same exact thing he meant
function smoke() if chp.Health <= 200 then core.Smoke.Enabled = true end chp.HealthChanged:connect(smoke) |
|
|
| Report Abuse |
|
|
gunter5
|
  |
| Joined: 15 Mar 2011 |
| Total Posts: 737 |
|
|
| 23 Jun 2015 03:16 PM |
do this if you dont understand what time said this is the same exact thing he meant
function smoke() if chp.Health <= 200 then core.Smoke.Enabled = true end chp.HealthChanged:connect(smoke)
you can do that or do this to ensure that smoke wont come out if the hp is not below 200
function smoke() if chp.Health <= 200 then core.Smoke.Enabled = true else core.Smoke.Enabled = false end end chp.HealthChanged:connect(smoke) |
|
|
| Report Abuse |
|
|
|
| 23 Jun 2015 03:42 PM |
| It works now thanks to an earlier post. Thank you though! |
|
|
| Report Abuse |
|
|