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 » Scripters
Home Search
 

Re: Nesting Functions Within Functions?

Previous Thread :: Next Thread 
MightyDantheman is not online. MightyDantheman
Joined: 06 May 2011
Total Posts: 5108
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 is not online. 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 is not online. 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
MightyDantheman is not online. MightyDantheman
Joined: 06 May 2011
Total Posts: 5108
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 is not online. 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
MightyDantheman is not online. MightyDantheman
Joined: 06 May 2011
Total Posts: 5108
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
MightyDantheman is not online. MightyDantheman
Joined: 06 May 2011
Total Posts: 5108
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
MightyDantheman is not online. MightyDantheman
Joined: 06 May 2011
Total Posts: 5108
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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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