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
 

Re: Learning to script

Previous Thread :: Next Thread 
cade2000 is not online. 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
islandmaker2012 is not online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
22 Feb 2014 08:16 PM
"WhoClicked" returns the player
So
WhoClicked.Character.Humanoid.Health = blablah
:)
Hope I helped
Report Abuse
cade2000 is not online. cade2000
Joined: 09 Aug 2009
Total Posts: 887
22 Feb 2014 08:16 PM
Wow thank you!
Report Abuse
islandmaker2012 is not online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
22 Feb 2014 08:17 PM
OR
Workspace[""..WhoClicked.Name..""].Humanoid.Health = blabla
Report Abuse
islandmaker2012 is not online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
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 is not online. 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 is not online. 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
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
22 Feb 2014 08:34 PM
You shouldn't be getting an error with your latest script .... o_O
Report Abuse
islandmaker2012 is not online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
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
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
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
islandmaker2012 is not online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
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
islandmaker2012 is not online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
22 Feb 2014 08:39 PM
@Agent,i believe hes trying to set the health
Report Abuse
cade2000 is not online. 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 is not online. cade2000
Joined: 09 Aug 2009
Total Posts: 887
22 Feb 2014 08:43 PM
Guys, guys, the above post.
Report Abuse
cade2000 is not online. 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
islandmaker2012 is not online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
22 Feb 2014 10:46 PM
Health isn't a member of the players Character is it?
Report Abuse
cade2000 is not online. 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
Thejustified is not online. Thejustified
Joined: 27 Jan 2013
Total Posts: 72
22 Feb 2014 11:43 PM
Health and MaxHealth :p
Report Abuse
islandmaker2012 is not online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
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
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