ferano
|
  |
| Joined: 23 Nov 2008 |
| Total Posts: 5094 |
|
|
| 06 Feb 2016 09:46 AM |
This script plays a sound when the players health changes, it is a local script in the starter pack
local humanoid = (game.Players.LocalPlayer.Character or game.Players.LocalCharacter.characterAdded:wait()):waitForChild("Humanoid")
humanoid.healthChanged:connect(function(_) script.Sound:play() end) |
|
|
| Report Abuse |
|
|
| |
|
ferano
|
  |
| Joined: 23 Nov 2008 |
| Total Posts: 5094 |
|
|
| 06 Feb 2016 09:55 AM |
Error message: Character is not a valid member of DataModel
Updated script: local humanoid = (game.Players.LocalPlayer.Character or game.Players.LocalCharacter.characterAdded:wait()):WaitForChild("Humanoid")
humanoid.HealthChanged:connect(function(_) script.Sound:play() end) |
|
|
| Report Abuse |
|
|
ferano
|
  |
| Joined: 23 Nov 2008 |
| Total Posts: 5094 |
|
| |
|
|
| 06 Feb 2016 10:08 AM |
| there's no way this works in studio.... |
|
|
| Report Abuse |
|
|
|
| 06 Feb 2016 10:09 AM |
this is so wrong on so many levels; that wouldn't even be the output
>.< troll? |
|
|
| Report Abuse |
|
|
ferano
|
  |
| Joined: 23 Nov 2008 |
| Total Posts: 5094 |
|
|
| 06 Feb 2016 10:31 AM |
| It works in studio, how is it wrong, the original script was yes, but I forgot some capitalization. That is in the updated script |
|
|
| Report Abuse |
|
|
ferano
|
  |
| Joined: 23 Nov 2008 |
| Total Posts: 5094 |
|
| |
|
ferano
|
  |
| Joined: 23 Nov 2008 |
| Total Posts: 5094 |
|
| |
|
|
| 06 Feb 2016 10:43 AM |
local p = game.Players.LocalPlayer repeat wait() until p.Character ~= nil local c = p.Character local h = c.Humanoid
h.Health.Changed:connect(function(val) script.Sound:play() end)
#Code print("Narwhals are our future") |
|
|
| Report Abuse |
|
|
ferano
|
  |
| Joined: 23 Nov 2008 |
| Total Posts: 5094 |
|
|
| 06 Feb 2016 10:45 AM |
@TheRobot
That does not work in studio or in server. |
|
|
| Report Abuse |
|
|
ferano
|
  |
| Joined: 23 Nov 2008 |
| Total Posts: 5094 |
|
| |
|
|
| 06 Feb 2016 11:01 AM |
oops
local h = c:WaitForChild("Humanoid") h.HealthChanged:connect(function()
fixes
#Code print("Narwhals are our future") |
|
|
| Report Abuse |
|
|
ferano
|
  |
| Joined: 23 Nov 2008 |
| Total Posts: 5094 |
|
|
| 06 Feb 2016 11:04 AM |
| It still does not work in server :/ |
|
|
| Report Abuse |
|
|
ferano
|
  |
| Joined: 23 Nov 2008 |
| Total Posts: 5094 |
|
| |
|
ferano
|
  |
| Joined: 23 Nov 2008 |
| Total Posts: 5094 |
|
| |
|
|
| 06 Feb 2016 12:00 PM |
@Rip I wrote this script, it does work in studio, it doesn't work in server because of a typo, what part of it makes you think it won't work?
@OP I fixed the typo, and tested in a server. I also had to add a wait because for some reason it was connecting the healthChanged event to a different humanoid...? Not sure whats going on.
wait() local humanoid = (game.Players.LocalPlayer.Character or game.Players.LocalPlayer.Character.characterAdded:wait()):waitForChild("Humanoid")
humanoid.healthChanged:connect(function(_) script.Sound:play() end) |
|
|
| Report Abuse |
|
|
ferano
|
  |
| Joined: 23 Nov 2008 |
| Total Posts: 5094 |
|
|
| 06 Feb 2016 12:10 PM |
| I fixed typos in the script already, but I haven't tried adding in a wait, thanks, I'll try that! Ya I don't think rip has an idea of what he is talking about with this though, it was fairly similar to the script I asked for help on and it makes a lot of sense |
|
|
| Report Abuse |
|
|
xlaser23
|
  |
| Joined: 10 Dec 2011 |
| Total Posts: 20341 |
|
|
| 06 Feb 2016 12:11 PM |
use this to define character local char = plr.Character or plr.CharacterAdded:wait()
http://www.roblox.com/xla-item?id=290739801http://www.roblox.com/aser-item?id=290739819http://www.roblox.com/23-item?id=290739831 R$346 Tx546 (づ ゚ ³ ゚)づ |
|
|
| Report Abuse |
|
|