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: Is there a way do reverse .Character?

Previous Thread :: Next Thread 
legokendall is not online. legokendall
Joined: 07 Aug 2010
Total Posts: 667
24 Jul 2014 04:33 PM
I know you can do game.Players.LocalPlayer.Character or whatever, but is there a way to trace the character back to the player? like humanoid.Parent.Player or something? Anyways if there isn't I need to know how to get back to the player :I
Report Abuse
super10099 is not online. super10099
Joined: 30 Jan 2010
Total Posts: 1102
24 Jul 2014 04:34 PM
game.Players.LocalPlayer

there
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
24 Jul 2014 04:35 PM
Game.Players:GetPlayerFromCharacter(character)
Report Abuse
ROBLOXTHEMOVIEs is not online. ROBLOXTHEMOVIEs
Joined: 11 Jun 2012
Total Posts: 5895
24 Jul 2014 04:35 PM
http://wiki.roblox.com/index.php?title=GetPlayerFromCharacter
Report Abuse
legokendall is not online. legokendall
Joined: 07 Aug 2010
Total Posts: 667
24 Jul 2014 04:36 PM
but would that work in a script for a brick? Like

function a(part)
game.LocalPlayer.Backpack.E:Destroy()

script.Parent.Touched:connect(a)

or something?
Report Abuse
legokendall is not online. legokendall
Joined: 07 Aug 2010
Total Posts: 667
24 Jul 2014 04:36 PM
oh nvm thanks
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
24 Jul 2014 04:37 PM
No. Use GetPlayerFromCharacter
Report Abuse
super10099 is not online. super10099
Joined: 30 Jan 2010
Total Posts: 1102
24 Jul 2014 04:37 PM
function a(part)
local player = game.Players:GetPlayerFromCharacter(part.Parent)
if player then
player.Backpack.E:Destroy()
end
script.Parent.Touched:connect(a)
Report Abuse
ROBLOXTHEMOVIEs is not online. ROBLOXTHEMOVIEs
Joined: 11 Jun 2012
Total Posts: 5895
24 Jul 2014 04:38 PM
script.Parent.Touched:connect(function(hit)
char = hit.Parent
p = game.Players:GetPlayerFromCharacter(char)
--code
end)
Report Abuse
128GB is not online. 128GB
Joined: 17 Apr 2014
Total Posts: 8056
24 Jul 2014 04:51 PM
script.Parent.Touched:connect(function(hit) < script.Parent.Touched:connect(onTouch)
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
24 Jul 2014 04:52 PM
They're basically the exact same.
Report Abuse
128GB is not online. 128GB
Joined: 17 Apr 2014
Total Posts: 8056
24 Jul 2014 04:58 PM
script.Parent.Touched:connect(function(hit)
creates a function every time it connects, making it slower and less efficient

script.Parent.Touched:connect(onTouch)
uses a function that already exist in the script making it faster and more efficient


at least someone told me that, I think it was AgentFireFox
Report Abuse
ROBLOXTHEMOVIEs is not online. ROBLOXTHEMOVIEs
Joined: 11 Jun 2012
Total Posts: 5895
24 Jul 2014 05:01 PM
Slower by like 1 millisecond.
No one would notice >.>
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
24 Jul 2014 05:03 PM
No, that's incorrect. I used to think that too but I realized how events are handled. That function is probably stored in a table and run when the event is invoked.
Report Abuse
128GB is not online. 128GB
Joined: 17 Apr 2014
Total Posts: 8056
24 Jul 2014 05:22 PM
:connect(onTouch), well actually I tested with a .Changed event but whatever
slowest time: 0.0000398159027
average time: 0.0000544559956


:connect(function(hit)
slowest time: 0.0000450611115
average time: 0.0000511808395


Testing in a loop that gave each one 1000 changes
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
24 Jul 2014 05:43 PM
Did you use a local function for the first one?
Report Abuse
128GB is not online. 128GB
Joined: 17 Apr 2014
Total Posts: 8056
24 Jul 2014 05:46 PM
No
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
24 Jul 2014 05:49 PM
Then it's probably the way roblox handles it, it won't keep creating a function because the argument of connect is a function, so all they have to do is call it--anonymous or not.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
24 Jul 2014 05:51 PM
Think about it this way:

function a(b)
b()
b()
b()
end

a(function() print("hi") end)

When you call the function, it's not recreating it, it's just using the one already stored in memory. Once that is done, the function should get GC'd
Report Abuse
128GB is not online. 128GB
Joined: 17 Apr 2014
Total Posts: 8056
24 Jul 2014 05:54 PM
Well someone told me it was created every time, I think it was you...
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
24 Jul 2014 05:55 PM
I don't remember ever saying it was created every time, or at least not about events.

But then again, it might of been ~1 year ago or so when I thought it was created every time.
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