|
| 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 |
|
|
|
| 24 Jul 2014 04:34 PM |
game.Players.LocalPlayer
there |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 24 Jul 2014 04:35 PM |
| Game.Players:GetPlayerFromCharacter(character) |
|
|
| Report Abuse |
|
|
|
| 24 Jul 2014 04:35 PM |
| http://wiki.roblox.com/index.php?title=GetPlayerFromCharacter |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
| |
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 24 Jul 2014 04:37 PM |
| No. Use GetPlayerFromCharacter |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 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
|
  |
| 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
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 24 Jul 2014 04:52 PM |
| They're basically the exact same. |
|
|
| Report Abuse |
|
|
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 |
|
|
|
| 24 Jul 2014 05:01 PM |
Slower by like 1 millisecond. No one would notice >.> |
|
|
| Report Abuse |
|
|
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
|
  |
| 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
|
  |
| 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
|
  |
| Joined: 17 Apr 2014 |
| Total Posts: 8056 |
|
| |
|
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
|
  |
| 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
|
  |
| 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
|
  |
| 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 |
|
|