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: ChildAdded Isn't Firing?

Previous Thread :: Next Thread 
powerhotmail123 is not online. powerhotmail123
Joined: 11 Apr 2011
Total Posts: 5041
03 Apr 2015 05:05 PM
Hey guys,

I am experiencing some trouble using ChildAdded. I'm using it to make a map loader, but it doesn't seem to fire. Here is the code:

MapHolder:ClearAllChildren()
BulletHolder:ClearAllChildren()
print("Removing map.")
GameStatusText.Value = "Removing current map."
wait(1)
local AllMaps = Maps:GetChildren()
local PartCount = 0
if MapStreak < 5 then
local MapR = AllMaps[math.random(1, #AllMaps)]
_G.RandomMap = MapR:Clone()
_G.RandomMap.Parent = MapHolder
local MapTable = {}
for i, v in pairs(MapR.Parts:GetChildren()) do
table.insert(MapTable, v)
end

GameStatusText.Value = "Currently loading ".._G.RandomMap.Name..", please wait a moment."
_G.RandomMap.Parts.ChildAdded:connect(function(child)
PartCount = PartCount + 1
local AllPartsNum = #MapTable
GameStatusText.Value = ("Parts loaded: "..PartCount.."/"..AllPartsNum)
end)
repeat wait() until PartCount == #MapTable
print(_G.RandomMap.Name.. " has been loaded.")

As you can see, I'm using a _G. variable, but I tried it using normal variables, but still it doesn't work. But why? I put a print inside the ChildAdded event, but it doesn't print. When I check inside MapHolder, there are lots of parts. The GameStatusText is also stuck at "Cureently loading ".._G.RandomMap.Name..", please wait a moment.". I also printed out PartCount, and that's at 0. And the number of parts in MapTable matches the number of parts in the physical map in ServerStorage. So what's wrong?

Thanks in advance!
Report Abuse
powerhotmail123 is not online. powerhotmail123
Joined: 11 Apr 2011
Total Posts: 5041
04 Apr 2015 02:10 AM
Also, Filtering Enabled is on and the script is in a server-script.
Report Abuse
lokkut is not online. lokkut
Joined: 18 Mar 2009
Total Posts: 1794
04 Apr 2015 02:13 AM
can iask why you're doing this?

Report Abuse
powerhotmail123 is not online. powerhotmail123
Joined: 11 Apr 2011
Total Posts: 5041
04 Apr 2015 02:17 AM
Yes, yes you can. :P

I'm doing this for a map loader. Because, before the game would wait around 5 seconds and then teleport the players to the map, when it isn't fully loaded. Some parts like the floor would not be loaded, and the player would fall through the map. This system, the one I made now, is supposed to stop that, waiting for all the parts in the model to be loaded.
Report Abuse
lokkut is not online. lokkut
Joined: 18 Mar 2009
Total Posts: 1794
04 Apr 2015 02:24 AM
Do GetChildren() on the original map ( the one before you copy it in )

and then do repeat wait() until NewMap:GetChildren() == #OriginalMapParts

or something like that
Report Abuse
powerhotmail123 is not online. powerhotmail123
Joined: 11 Apr 2011
Total Posts: 5041
04 Apr 2015 02:26 AM
But, at the same time, I would like the GUI I have to show how much parts are loading, so the player doesn't get confused and leaves because he/she thinks the game is broken or what-not.

I would just like to know, why ChildAdded isn't firing.
Report Abuse
lokkut is not online. lokkut
Joined: 18 Mar 2009
Total Posts: 1794
04 Apr 2015 02:27 AM
because it's useless

tbh it would jsut cause more lag than my suggestion anyway, and if you want to show how many parts are in the game just put in the repeat loop
Report Abuse
lokkut is not online. lokkut
Joined: 18 Mar 2009
Total Posts: 1794
04 Apr 2015 02:30 AM
if you want the serious answer it's because when the clone happens, all parts are instantly added
so you would need to put the ChildAdded event in front of the clone
Report Abuse
powerhotmail123 is not online. powerhotmail123
Joined: 11 Apr 2011
Total Posts: 5041
04 Apr 2015 02:30 AM
But how would I change the text? The repeat loop will yield the script.
Report Abuse
lokkut is not online. lokkut
Joined: 18 Mar 2009
Total Posts: 1794
04 Apr 2015 02:31 AM
function changetext()
--body
end

repeat wait() changetext() until --blah blah blah
Report Abuse
powerhotmail123 is not online. powerhotmail123
Joined: 11 Apr 2011
Total Posts: 5041
04 Apr 2015 02:31 AM
Ahh, that may be the answer. Thanks! <3
Report Abuse
powerhotmail123 is not online. powerhotmail123
Joined: 11 Apr 2011
Total Posts: 5041
04 Apr 2015 07:21 AM
Ok, so I'm using the method you used, but it didn't work. It says all the parts have loaded, but when the script teleports the players to the map, parts (including the floor) were not loading, leading to them falling off..
Here is my script:

MapHolder:ClearAllChildren()
BulletHolder:ClearAllChildren()
print(script.Name..": Removing map.")
GameStatusText.Value = "Removing current map."
wait(1)
local AllMaps = Maps:GetChildren()
local PartCount = 0

--Map loading function
local function LoadMap(MapTable, PartCount)
if MapTable ~= nil and PartCount ~= nil then
local AllPartsNum = MapTable
GameStatusText.Value = "Parts Loaded: "..PartCount.."/"..AllPartsNum
print(script.Name..": Parts Loaded: "..PartCount.."/"..AllPartsNum)
end
end

if MapStreak < 5 then
local MapR = AllMaps[math.random(1, #AllMaps)]
_G.RandomMap = MapR:Clone()
_G.RandomMap.Parent = MapHolder
local MapTable = MapR.Parts:GetChildren()
local MapInWS = MapHolder:WaitForChild(_G.RandomMap.Name)
local MapChildrenR = MapInWS.Parts:GetChildren()

GameStatusText.Value = "Currently loading ".._G.RandomMap.Name..", please wait a moment."
print(script.Name..": Currently loading ".._G.RandomMap.Name..", please wait a moment.")

repeat LoadMap(#MapTable, #MapChildrenR) wait(1) until #MapChildrenR == #MapTable
print(script.Name..": ".._G.RandomMap.Name.. " has been loaded.")

It goes past the last line, but the map isn't fully loaded. What seems to be the problem?
Report Abuse
Atrulable is not online. Atrulable
Joined: 19 Dec 2008
Total Posts: 2543
04 Apr 2015 07:25 AM
The thing is that some clients are going to take longer to load the map then others, this means that some people are still going to fall through the floor unless you have FilteringEnabled set to false which will rectify it.

Your best bet is to make the map load right after the other one is gone so during the intermission it can load for everyone.

Also have the map close to where the people wait, not sure but streaming and filtering enabled might cause bricks to not loads even after 30 seconds and not until the player is right by it.
Report Abuse
powerhotmail123 is not online. powerhotmail123
Joined: 11 Apr 2011
Total Posts: 5041
04 Apr 2015 07:27 AM
How would Filtering change it?
Report Abuse
Atrulable is not online. Atrulable
Joined: 19 Dec 2008
Total Posts: 2543
04 Apr 2015 07:29 AM
Because the server won't be able to see if each part is loaded for the client. Filtering creates a massive gap between the client and the server which means you are limited in what you can do with parts in Workspace. You might be able to do it with RemoteFunctions and then each player has a LocalScript which checks and if all of them are true then the script continues, but it's a guess.
Report Abuse
powerhotmail123 is not online. powerhotmail123
Joined: 11 Apr 2011
Total Posts: 5041
04 Apr 2015 07:30 AM
Ok, so I justed tested it without Filtering, and the same problem persists.
Report Abuse
Atrulable is not online. Atrulable
Joined: 19 Dec 2008
Total Posts: 2543
04 Apr 2015 07:32 AM
Interesting, unless it's something that's been changed. Give the LocalScript idea a try it might help for the client to check the bricks.

You might not be able to, think about it all the bricks are in the model no matter what they just haven't rendered and there isn't away of checking if they're rendered or not.
Report Abuse
powerhotmail123 is not online. powerhotmail123
Joined: 11 Apr 2011
Total Posts: 5041
04 Apr 2015 08:01 AM
I'll try that; but how did Taymaster do it? In his game, Twisted Murderer, he was able to make a map loader, which is similar to mines.
Report Abuse
powerhotmail123 is not online. powerhotmail123
Joined: 11 Apr 2011
Total Posts: 5041
04 Apr 2015 08:12 AM
Any ideas?
Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
04 Apr 2015 08:19 AM
Preload your maps to ReplicatedStorage, or send a RemoteFunction to all clients with the total amount of Instances in the map and make them return when it matches. When all clients return, all clients are loaded.
Report Abuse
powerhotmail123 is not online. powerhotmail123
Joined: 11 Apr 2011
Total Posts: 5041
04 Apr 2015 08:22 AM
What do you mean 'Preload your maps to ReplicatedStorage'? Do you mean keeping the maps within ServerStorage?
Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
04 Apr 2015 08:27 AM
No I mean move/clone them to ReplicatedStorage before they're needed so that the client only has to know the Parent property changed in the model.
Report Abuse
powerhotmail123 is not online. powerhotmail123
Joined: 11 Apr 2011
Total Posts: 5041
04 Apr 2015 08:34 AM
Ok, so I made a folder in ReplicatedStorage to put the map in. Is this fine?

local MapR = AllMaps[math.random(1, #AllMaps)]
_G.RandomMap = MapR:Clone()
_G.RandomMap.Parent = ReplicatedStorage
local MapTable = MapR.Parts:GetChildren()
local MapInWS = MapHolder:WaitForChild(_G.RandomMap.Name)
local MapChildrenR = MapInWS.Parts:GetChildren()

GameStatusText.Value = "Currently loading ".._G.RandomMap.Name..", please wait a moment."
print(script.Name..": Currently loading ".._G.RandomMap.Name..", please wait a moment.")

while #MapChildrenR ~= #MapTable do
GameStatusText.Value = "Parts loaded: "..#MapChildrenR.."/"..#MapTable
wait(0.1)
end

_G.RandomMap.Parent = PreloadingMap
Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
04 Apr 2015 08:37 AM
Current map --> Parent = workspace;
Choose next --> Parent = ReplicatedStorage

repeat
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