|
| 02 Mar 2017 01:00 AM |
Is it not possible to nest functions within functions? I tried to add a player added function inside of a module function, but I don't think the function fired. What's going on?
~MightyDantheman~ |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 02 Mar 2017 01:00 AM |
| It's possible, but make sure you're doing it right. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 02 Mar 2017 01:01 AM |
| It'd be helpful if you posted what you tried :_( |
|
|
| Report Abuse |
|
|
|
| 02 Mar 2017 01:02 AM |
local m = {}
function m.run() local r = nil local i = 1 while i < math.random(1,10) do if r == nil then r = math.random(0,9) else r = r..math.random(0,9) end end game.Players.PlayerAdded:connect(function(p) print("test") if p then local g = Instance.new("ScreenGui",game.Players:FindFirstChild(p.Name).PlayerGui) g.Name = r g.ResetOnSpawn = false end end) end
return m
~MightyDantheman~ |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 02 Mar 2017 01:06 AM |
add a print _right before_ you start listening for playeradded. If that's not ever printed, your problem is either: - you never call m.run - the while loop never terminates (which statistically should be impossible) or something else
Anyways another problem is that PlayerGui is in their player object, not their character. So:
Instance.new("ScreenGui", p:WaitForChild("PlayerGui")) |
|
|
| Report Abuse |
|
|
|
| 02 Mar 2017 01:09 AM |
'test2' prints with this, but not 'test':
local m = {}
function m.run() local r = nil local i = 1 while i < math.random(1,10) do if r == nil then r = math.random(0,9) else r = r..math.random(0,9) end end print("test2") game.Players.PlayerAdded:connect(function(p) print("test") if p then local g = Instance.new("ScreenGui",game.Players:FindFirstChild(p.Name).PlayerGui) g.Name = r g.ResetOnSpawn = false end end) end
return m
--//
~MightyDantheman~ |
|
|
| Report Abuse |
|
|
|
| 02 Mar 2017 01:11 AM |
I'll probably just replace the loop with the player's PlayerId, but that still won't fix this issue.
~MightyDantheman~ |
|
|
| Report Abuse |
|
|
|
| 02 Mar 2017 01:13 AM |
Actually, I think the issue is that the player loads too quickly in the studio test. It worked fine with a server test.
~MightyDantheman~ |
|
|
| Report Abuse |
|
|