cade2000
|
  |
| Joined: 09 Aug 2009 |
| Total Posts: 887 |
|
|
| 22 Feb 2014 08:13 PM |
function potato(WhoClicked) print 'Hello world!' game.Workspace.WhoClicked.Humanoid.Health = game.Workspace.WhoClicked.Humanoid.Health - 5 -- WhoClicked:remove() end
script.Parent.ClickDetector.MouseClick:connect(potato)
So I'm learning how to script, and I'm making a brick in which you click you lose 5 health. All works fine till I put in the
game.Workspace.WhoClicked.Humanoid.Health = game.Workspace.WhoClicked.Humanoid.Health - 5
part.
I have the click detector, everything works fine, it's the above part that's have the problem. |
|
|
| Report Abuse |
|
|
|
| 22 Feb 2014 08:16 PM |
"WhoClicked" returns the player So WhoClicked.Character.Humanoid.Health = blablah :) Hope I helped |
|
|
| Report Abuse |
|
|
cade2000
|
  |
| Joined: 09 Aug 2009 |
| Total Posts: 887 |
|
| |
|
|
| 22 Feb 2014 08:17 PM |
OR Workspace[""..WhoClicked.Name..""].Humanoid.Health = blabla |
|
|
| Report Abuse |
|
|
|
| 22 Feb 2014 08:19 PM |
@cade,np,you had the right idea but "WhoClicked.Character" Or Workspace[""..WhoClicked.Name..""] Was the correct thing,u were close :) |
|
|
| Report Abuse |
|
|
cade2000
|
  |
| Joined: 09 Aug 2009 |
| Total Posts: 887 |
|
|
| 22 Feb 2014 08:24 PM |
Awesome! Thanks a lot, also I'm trying to use different types of programs to get the hang of this. What did I do wrong here? "attempt to call a nill value"
newHealth = game.Lighting.NewHealth:clone() function onSpawn(WhoSpawned) WhoSpawned.Character.Health:remove() newHealth.Parent = WhoSpawned.Character end
game.Players.ChildAdded:connect(onSpawn) |
|
|
| Report Abuse |
|
|
cade2000
|
  |
| Joined: 09 Aug 2009 |
| Total Posts: 887 |
|
|
| 22 Feb 2014 08:30 PM |
| prolly no one is looking at this cuz they think it's been solved lol |
|
|
| Report Abuse |
|
|
|
| 22 Feb 2014 08:34 PM |
| You shouldn't be getting an error with your latest script .... o_O |
|
|
| Report Abuse |
|
|
|
| 22 Feb 2014 08:36 PM |
well im glad your learning to script,ill help ya out first off,ChildAdded works,but its better to use PlayerAdded so game.Players.PlayerAdded:connect(function(NewPlayer)--runs when a player joins NewPlayer.CharacterAdded:connect(function(NewChar)--waits for the character,then runs --NewChar.Humanoid:destroy() u can use this,but itll make the animations stop.. --Instead,do this NewChar.Humanoid.Health = numberhere--ex:100,50,10,math.huge end)--ends the CharacterAdded Function end)--ends the PlayerAdded Function NOTE: humanoid has several properties: so defining them like a hierarchy: Humanoid -Health -WalkSpeed -MaxHealth
|
|
|
| Report Abuse |
|
|
|
| 22 Feb 2014 08:37 PM |
Actually, looking over it again, there is a functionality flaw. When a player spawns, their character spawns in workspace (is added to workspace).
However, the player object itself has a nice CharacterAdded event that fires when the character is changed.
What are you trying to do with that code? As far as I know, there's no 'Health' object inside the player's character. |
|
|
| Report Abuse |
|
|
|
| 22 Feb 2014 08:38 PM |
but,for your sake,ill simplify it
function PlayerJoined(NewPlayer) NewPlayer.CharacterAdded:connect(CharacterAdded)--runs the function "CharacterAdded" end
function CharacterAdded (Char) Char.Humanoid.Health = 50 -- sets health to 50,regular is 100 Char.Humanoid.WalkSpeed = 30--running speed!:D 16 is regular speed end
game.Players.PlayerAdded:connect(PlayerJoined)--runs the function "PlayerJoined" |
|
|
| Report Abuse |
|
|
|
| 22 Feb 2014 08:39 PM |
| @Agent,i believe hes trying to set the health |
|
|
| Report Abuse |
|
|
cade2000
|
  |
| Joined: 09 Aug 2009 |
| Total Posts: 887 |
|
|
| 22 Feb 2014 08:40 PM |
WhoSpawned.Character.Health (Health is a script inside the character that determines health regen and such)
I'm switching the scripts out with one in the lighting. so I'm removing the original one, and adding the new one from lighting.
Here's my latest version.
function onSpawn(WhoSpawned) WhoSpawned.Character.Health:remove() game.Lighting.NewHealth:clone().Parent = WhoSpawned.Character end
game.Players.PlayerAdded:connect(onSpawn) |
|
|
| Report Abuse |
|
|
cade2000
|
  |
| Joined: 09 Aug 2009 |
| Total Posts: 887 |
|
|
| 22 Feb 2014 08:43 PM |
| Guys, guys, the above post. |
|
|
| Report Abuse |
|
|
cade2000
|
  |
| Joined: 09 Aug 2009 |
| Total Posts: 887 |
|
|
| 22 Feb 2014 08:55 PM |
| So do you guys not know what's going wrong? |
|
|
| Report Abuse |
|
|
|
| 22 Feb 2014 10:46 PM |
| Health isn't a member of the players Character is it? |
|
|
| Report Abuse |
|
|
cade2000
|
  |
| Joined: 09 Aug 2009 |
| Total Posts: 887 |
|
|
| 22 Feb 2014 11:02 PM |
Yes it is. It's a script named health.
|
|
|
| Report Abuse |
|
|
| |
|
|
| 22 Feb 2014 11:51 PM |
Instead of removing the health script Put this in workspace
game.Players.PlayerAdded:connect(function(p) p.CharacterAdded:connect(function(c) s = game.Lighting.HpRegen:clone() s.Parent = c end) end)
And then put a script named "HpRegen" in lighting,and put THIS into it: while wait(0.5) do H = script.Parent.Humanoid H.Health = H.Health+1 end
Thisll make it go up faster,change the time in wait(0.5) to whatever suits your needs Too fast? Change the 0.5 to higher wait time,like 1 or 2 while wait(2) do Anyways,just do as I posted here,and health will go up quicker,rather than deleting the health script there,add a new one,and keep both Health will still go up :) |
|
|
| Report Abuse |
|
|