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
|
  |
| Joined: 31 Jan 2014 |
| Total Posts: 115 |
|
| |
|
|
| 20 Aug 2017 05:43 AM |
| Backpack is not a child of Players, silly |
|
|
| Report Abuse |
|
|
hokyboy
|
  |
| Joined: 31 Jan 2014 |
| Total Posts: 115 |
|
| |
|
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 |
|
|
|
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| Joined: 31 Jan 2014 |
| Total Posts: 115 |
|
|
| 20 Aug 2017 05:47 AM |
| but every chaceter needs to get a gun |
|
|
| Report Abuse |
|
|
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
|
  |
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 20 Aug 2017 07:09 AM |
| Wouldn't you need to identify the player as LocalPlayer? |
|
|
| Report Abuse |
|
|
LaeMVP
|
  |
| Joined: 24 Jun 2013 |
| Total Posts: 4416 |
|
|
| 20 Aug 2017 07:09 AM |
| game.ServerStorage[string.char(64 + ChoosenMap)] |
|
|
| Report Abuse |
|
|