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 » Scripting Helpers
Home Search
 

HealthChanged()

Previous Thread :: Next Thread 
VisualGraphics is not online. VisualGraphics
Joined: 26 Nov 2010
Total Posts: 6515
06 Aug 2014 09:06 PM
backstory - when you have .3% of your health a music plays else music stops

problem - output says 'attempt to index local 'E' (a nil value)'


local P = game.Players.LocalPlayer
local E = P.Character

E.Humanoid.HealthChanged:connect(function()
if E then
if E.Humanoid.Health <= E.Humanoid.MaxHealth * .3 then
E.Humanoid.WalkSpeed = 11
script.Cliff:Play()
elseif
E.Humanoid.Health > E.Humanoid.MaxHealth * .3 then
E.Humanoid.WalkSpeed = 16
script.Cliff:Stop()
end
end
end)
Report Abuse
Infocus is not online. Infocus
Joined: 28 Apr 2011
Total Posts: 8022
06 Aug 2014 09:11 PM

local P = game.Players.LocalPlayer
local E = P.Character
repeat wait() until E

E.Humanoid.HealthChanged:connect(function(h)
if h <= E.Humanoid.MaxHealth * .3 then
E.Humanoid.WalkSpeed = 11
script.Cliff:Play()
elseif
h > E.Humanoid.MaxHealth * .3 then
E.Humanoid.WalkSpeed = 16
script.Cliff:Stop()
end
end)
Report Abuse
VisualGraphics is not online. VisualGraphics
Joined: 26 Nov 2010
Total Posts: 6515
06 Aug 2014 09:21 PM
it works in studios but not online
qqq
Report Abuse
Infocus is not online. Infocus
Joined: 28 Apr 2011
Total Posts: 8022
06 Aug 2014 09:22 PM
Add this to the top
repeat wait() until game.Players.LocalPlayer
Report Abuse
DeSpizer27 is not online. DeSpizer27
Joined: 13 Jul 2012
Total Posts: 2679
06 Aug 2014 09:22 PM
LocalPlayer only works in a LocalScript in the StarterPack or StarterGui or anything inside the Player.

In solo it would work in a normal script but for it to work in the expected online mode, put it in a localscript.
Report Abuse
DragonODeath is not online. DragonODeath
Joined: 02 May 2011
Total Posts: 1252
06 Aug 2014 09:23 PM
wow infocus rly bro y u no no. u has to do dis

local P = game.Players.LocalPlayer
repeat wait() until P.Character
local E = P. Character
Report Abuse
SenseiWarrior is not online. SenseiWarrior
Joined: 09 Apr 2011
Total Posts: 12140
06 Aug 2014 09:23 PM
local P = game.Players.LocalPlayer
repeat wait() until P
local E = Workspace:WaitForChild(P.Name)

E.Humanoid.HealthChanged:connect(function()
if E then
if E.Humanoid.Health <= E.Humanoid.MaxHealth * .3 then
E.Humanoid.WalkSpeed = 11
script.Cliff:Play()
elseif
E.Humanoid.Health > E.Humanoid.MaxHealth * .3 then
E.Humanoid.WalkSpeed = 16
script.Cliff:Stop()
end
end
end)
Report Abuse
Infocus is not online. Infocus
Joined: 28 Apr 2011
Total Posts: 8022
06 Aug 2014 09:23 PM
Already did @drag

Look at first post.

Gg no re
Report Abuse
VisualGraphics is not online. VisualGraphics
Joined: 26 Nov 2010
Total Posts: 6515
06 Aug 2014 09:29 PM
@SenseiWarrior @Infocus
thanks for help

@DeSpizer27
i know
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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