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: Why FindFirstChild wont work

Previous Thread :: Next Thread 
hokyboy is not online. hokyboy
Joined: 31 Jan 2014
Total Posts: 115
20 Aug 2017 05:41 AM
while true do
CoosenMap = math.random(1,5)
if CoosenMap == 1 then
game.ServerStorage.A:Clone().Parent = game.Workspace
wait(2)
game.ServerStorage.ActiveGuns:Clone().Parent = game.Players:FindFirstChild("Backpack") --- error line
wait(10)
game.Workspace.A:Destroy()
end
if CoosenMap == 2 then
game.ServerStorage.B:Clone().Parent = game.Workspace
wait(2)
game.Workspace.B:Destroy()
end
end
Report Abuse
hokyboy is not online. hokyboy
Joined: 31 Jan 2014
Total Posts: 115
20 Aug 2017 05:42 AM
ActiveGuns is a folder
Report Abuse
Flubberlutsch is not online. Flubberlutsch
Joined: 27 Sep 2016
Total Posts: 188
20 Aug 2017 05:43 AM
Backpack is not a child of Players, silly
Report Abuse
hokyboy is not online. hokyboy
Joined: 31 Jan 2014
Total Posts: 115
20 Aug 2017 05:44 AM
were is it then form???
Report Abuse
Ajastra is not online. Ajastra
Joined: 01 Aug 2017
Total Posts: 1461
20 Aug 2017 05:44 AM
Hey, you should convert the maps into a table by putting all maps in a folder and using Instance:GetChildren().

To get a random child from a table:

aTable[math.random(#aTable)]

This is much more dynamic solution.

Additionally, you attempted to clone and parent to game.Players.Backpack. Individual players have a backpack, but you were referencing the game.Players service.

I'm also not sure what the error was on that line, perhaps game.ServerStorage.ActiveGuns is nil.


Report Abuse
TakeoHonorable is online. TakeoHonorable
Joined: 25 Jul 2012
Total Posts: 149
20 Aug 2017 05:45 AM
"game.ServerStorage.ActiveGuns:Clone().Parent = game.Players:FindFirstChild("Backpack") --- error line"

^The line lacks a player instance to find the backpack. It should be typed something as:

game.ServerStorage.ActiveGuns:Clone().Parent = game.Players:FindFirstChild(PLAYERNAMEGOESHERE):FindFirstChild("Backpack")


Report Abuse
Ajastra is not online. Ajastra
Joined: 01 Aug 2017
Total Posts: 1461
20 Aug 2017 05:45 AM
Also, there's a typo in your variable name, it should be "chosen".


Report Abuse
hokyboy is not online. hokyboy
Joined: 31 Jan 2014
Total Posts: 115
20 Aug 2017 05:46 AM
while true do
CoosenMap = math.random(1,5)
if CoosenMap == 1 then
game.ServerStorage.A:Clone().Parent = game.Workspace
wait(2)
game.ServerStorage.ActiveGuns:Clone().Parent = game.Players.Player:FindFirstChild("Backpack")
wait(10)
game.Workspace.A:Destroy()
end
if CoosenMap == 2 then
game.ServerStorage.B:Clone().Parent = game.Workspace
wait(2)
game.Workspace.B:Destroy()
end
end
Report Abuse
Ajastra is not online. Ajastra
Joined: 01 Aug 2017
Total Posts: 1461
20 Aug 2017 05:47 AM
Player probably won't be a valid member of game.Players.

Additionally, cloning and parenting to nil wouldn't cause an error, but OP hasn't posted the error output.


Report Abuse
hokyboy is not online. hokyboy
Joined: 31 Jan 2014
Total Posts: 115
20 Aug 2017 05:47 AM
but every chaceter needs to get a gun
Report Abuse
Ajastra is not online. Ajastra
Joined: 01 Aug 2017
Total Posts: 1461
20 Aug 2017 05:49 AM
You need to use a loop to do something to all players. Loop through the table game.Players:GetPlayers() returns. For each player, clone a weapon to their backpack.

:)


Report Abuse
Rockenite is not online. Rockenite
Joined: 20 Dec 2011
Total Posts: 1444
20 Aug 2017 05:50 AM
while true do
CoosenMap = math.random(1,5)
if CoosenMap == 1 then
game.ServerStorage.A:Clone().Parent = game.Workspace
wait(2)
for i,v in pairs(game.Players:GetChilden()) do
game.ServerStorage.ActiveGuns:Clone().Parent = v:FindFirstChild("Backpack")
end
wait(10)
game.Workspace.A:Destroy()
end
if CoosenMap == 2 then
game.ServerStorage.B:Clone().Parent = game.Workspace
wait(2)
game.Workspace.B:Destroy()
end
end


Report Abuse
TakeoHonorable is online. TakeoHonorable
Joined: 25 Jul 2012
Total Posts: 149
20 Aug 2017 05:53 AM
while true do
CoosenMap = math.random(1,5)
if CoosenMap == 1 then
game.ServerStorage.A:Clone().Parent = game.Workspace
wait(2)
for _,v in pairs(game.Players:GetPlayers()) do
game.ServerStorage.ActiveGuns:Clone().Parent = v:FindFirstChild("Backpack")
end
wait(10)
game.Workspace.A:Destroy()
end
if CoosenMap == 2 then
game.ServerStorage.B:Clone().Parent = game.Workspace
wait(2)
game.Workspace.B:Destroy()
end
end


Report Abuse
RedstoneMic is not online. RedstoneMic
Joined: 13 Feb 2016
Total Posts: 25
20 Aug 2017 07:00 AM
Backpack is not a member of Players, It is a member of any player.

So it should be game.Players.Player1:FindFirstChild("Backpack") or on someone else or in a loop on everyone
Report Abuse
TheGamerElite05 is not online. TheGamerElite05
Joined: 18 Sep 2016
Total Posts: 62
20 Aug 2017 07:09 AM
Wouldn't you need to identify the player as LocalPlayer?
Report Abuse
LaeMVP is online. LaeMVP
Joined: 24 Jun 2013
Total Posts: 4416
20 Aug 2017 07:09 AM
game.ServerStorage[string.char(64 + ChoosenMap)]
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