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: Reconnecting a function

Previous Thread :: Next Thread 
Scriptural is not online. Scriptural
Joined: 06 Sep 2013
Total Posts: 2979
09 Sep 2013 09:40 PM
Likes say I have a function like this

Game.Players.Scriptural.Character.Humanoid.HealthChanged:connect(function()
print(Game.Players.Scriptural.Character.Humanoid.Health)
end

That works fine, but what if my humanoid got removed, and I added in a new one, the script stops working because the humanoid I had it connected to is no longer there, so how would I auto reconnect the function the new humanoid if something like that happened?
Report Abuse
Lapwn is not online. Lapwn
Joined: 03 Jun 2012
Total Posts: 5975
09 Sep 2013 09:41 PM
minimize g
Report Abuse
Scriptural is not online. Scriptural
Joined: 06 Sep 2013
Total Posts: 2979
09 Sep 2013 09:41 PM
No. I like using Game, and it works just as well as game.
Report Abuse
pieshop97 is not online. pieshop97
Joined: 11 Mar 2011
Total Posts: 550
09 Sep 2013 09:46 PM
Clone the deleted humanoid. DERP
Report Abuse
Scriptural is not online. Scriptural
Joined: 06 Sep 2013
Total Posts: 2979
09 Sep 2013 09:47 PM
Again not what I asked...
Report Abuse
Lapwn is not online. Lapwn
Joined: 03 Jun 2012
Total Posts: 5975
09 Sep 2013 09:48 PM

m=game.Players.Scriptural.Character.
m.Humanoid.HealthChanged:connect(function()
print(m.Humanoid.Health)
end

f=m:Clone()
f.Parent=m
Report Abuse
Scriptural is not online. Scriptural
Joined: 06 Sep 2013
Total Posts: 2979
09 Sep 2013 09:49 PM
Thats not what I asked at all, I'm not sure what you are doing. Thanks for trying, I'm not really sure how to explain what I need.
Report Abuse
chaokid9 is not online. chaokid9
Joined: 29 Aug 2008
Total Posts: 6187
09 Sep 2013 09:50 PM
while wait() do
x = Game.Players.Scriptural.Character
end
x.Humanoid.HealthChanged:connect(function()
print(x.Humanoid.Health)
end

That should do it.
This way it is constantly updating the character.
Report Abuse
Lapwn is not online. Lapwn
Joined: 03 Jun 2012
Total Posts: 5975
09 Sep 2013 09:50 PM
oh I get it

for _,v in pairs(game.Players.LocalPlayer) do
if v.Name=="Scriptual" then
v.Character.Humanoid.HealthChanged:connect(function()
print(v.Character.Humanoid.Health)
end
Report Abuse
Lapwn is not online. Lapwn
Joined: 03 Jun 2012
Total Posts: 5975
09 Sep 2013 09:51 PM
forgot an end sorry
Report Abuse
Scriptural is not online. Scriptural
Joined: 06 Sep 2013
Total Posts: 2979
09 Sep 2013 09:53 PM
@Chao
The only problem with that is it will connect the function more than once
Report Abuse
chaokid9 is not online. chaokid9
Joined: 29 Aug 2008
Total Posts: 6187
09 Sep 2013 09:54 PM
Why is that?
Report Abuse
pieshop97 is not online. pieshop97
Joined: 11 Mar 2011
Total Posts: 550
09 Sep 2013 09:54 PM
I'll explain what I meant then...

Okay, so DON'T add a new humanoid, before you delete the humanoid in the first place, make it where it clones the humanoid after it is deleted, therefore making the script function correct because the humanoid is still there, just cloned.
Report Abuse
Scriptural is not online. Scriptural
Joined: 06 Sep 2013
Total Posts: 2979
09 Sep 2013 09:57 PM
while wait(0.03) do
--Stuff I'm too lazy to type out that connects the function
end

That would connect the function every 0.03 seconds

@Pie
What I need is for if the humanoid gets removed for some reason, not a currently known one, it will automaticly connect it to the new humanoid.
Report Abuse
chaokid9 is not online. chaokid9
Joined: 29 Aug 2008
Total Posts: 6187
09 Sep 2013 09:59 PM
Yeah, but it is not in the 'while wait() do' it is completely separate. Maybe you are right, but it looks fine to me.
Report Abuse
Scriptural is not online. Scriptural
Joined: 06 Sep 2013
Total Posts: 2979
09 Sep 2013 10:00 PM
Oh I see, well in that case it would never connect the function at all
Report Abuse
chaokid9 is not online. chaokid9
Joined: 29 Aug 2008
Total Posts: 6187
09 Sep 2013 10:02 PM
Why not? If that is true and worst comes to worst you could just use tow scripts and a physical variable.
Report Abuse
Scriptural is not online. Scriptural
Joined: 06 Sep 2013
Total Posts: 2979
09 Sep 2013 10:04 PM
while wait(0.03) do --Forever loop
--Blah blah set variable
end --Ends loop, that will always repeat, so what is below doesn't matter
--Connect function, but this part will never run because of the loop.
Report Abuse
lucas668 is not online. lucas668
Joined: 18 Jun 2008
Total Posts: 6183
09 Sep 2013 10:10 PM
p = Game.Players.Scriptural
con;

function Connector(humanoid)

if humanoid:IsA("Humanoid") then

con = nil

con = humanoid.HealthChanged:connect(function(newhealth)
print(newhealth)
end)

end
end

p.CharacterAdded:connect(function()
if p.Character:FindFirstChild("Humanoid") then
Connector(p.Character.Humanoid)
end
end)

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