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: Can you put objects into tables?

Previous Thread :: Next Thread 
LuluPls is not online. LuluPls
Joined: 23 Aug 2010
Total Posts: 1221
13 Feb 2017 09:26 AM
I'm trying to teleport all players to non-occupied spawns

The spawns are located in game.Workspace.First.FirstLevelSpawns and each have a boolvalue caled "Occupied" inside it.
For each player I want to check if the part is occupied. If it is then I want to repick, if it isn't I want it to change the value of Occupied to true and teleport them to that respective part.

This is my function so far, any help is appreciated:


function Startgame()
--Teleporting all players to spawns
tab={}
for i,v in pairs(game.Workspace:WaitForChild("First"):WaitForChild("FirstLevelSpawns"):GetChildren()) do
table.insert(tab,v)
end
for i,v in pairs(game.Players:GetChildren()) do
for i,c in pairs(tab) do
if c.Occupied.Value==false then
v.Character:MoveTo(c.Position)
--else

end
end
end
end
Report Abuse
LuluPls is not online. LuluPls
Joined: 23 Aug 2010
Total Posts: 1221
13 Feb 2017 09:27 AM
I'm aware I have a few extra ends on there, this isn't the entire function.
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
13 Feb 2017 09:35 AM
local spawns = workspace.First.FirstLevelSpawns:GetChildren()

for i,v in next, game.Players:GetPlayers() do
v.Character:MoveTo(spawns[i].Position)
end


Report Abuse
coolrainbow2221 is not online. coolrainbow2221
Joined: 28 Jan 2017
Total Posts: 957
13 Feb 2017 09:49 AM
not smart cuz u can never guarantee how many spawns there r in comparison to players
Report Abuse
Xonae is online. Xonae
Joined: 04 Dec 2013
Total Posts: 336
13 Feb 2017 10:22 AM
Make sure you have enough spawns for each player, if each player is teleported to a unique spawn.

function FindSpawn()
local spawns=game.Workspace.First.FirstLevelSpawns:GetChildren()
local newspawn
while true do
local spawn=spawns[math.random(1,#spawns)]
if spawn.Occupied.Value==false then
spawn.Occupied.Value=true -- feel free to remove this and replace it somewhere else
newspawn=spawn
break
end
end

return newspawn
end

this function will find a random spawn that isn't occupied, this function will however crash your game if there are no longer any spawns that can be occupied.


~ Xonae ~
Report Abuse
LuluPls is not online. LuluPls
Joined: 23 Aug 2010
Total Posts: 1221
15 Feb 2017 06:59 AM
Thanks TimeTicks. I don't know how I didn't think of that.
Report Abuse
HalfPinky456 is not online. HalfPinky456
Joined: 10 Apr 2011
Total Posts: 6236
15 Feb 2017 07:09 AM
coolrainbow, don't try helping if you have no idea what is going on
Report Abuse
OzzyFin is not online. OzzyFin
Joined: 07 Jun 2011
Total Posts: 3600
15 Feb 2017 07:28 AM
If you want to randomize the spawns a little bit:

local players = game.Players:GetPlayers()
table.sort(players,function(x,y)
return math.random(2) == 1
end)

then iterate through 'players'
Report Abuse
coolrainbow2221 is not online. coolrainbow2221
Joined: 28 Jan 2017
Total Posts: 957
17 Feb 2017 09:53 AM
@half

no, you're just too idiotic to understand the approach kid
Report Abuse
LuluPls is not online. LuluPls
Joined: 23 Aug 2010
Total Posts: 1221
17 Feb 2017 02:14 PM
Half is right though, you're stupid.


Report Abuse
coolrainbow2221 is not online. coolrainbow2221
Joined: 28 Jan 2017
Total Posts: 957
18 Feb 2017 12:30 AM
omg you're both so dull


it doesnt check if you have enough spawns ffs
Report Abuse
npott13 is not online. npott13
Joined: 19 Dec 2010
Total Posts: 264
18 Feb 2017 02:59 AM
coolrainbow, please tell me ur joking...
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
18 Feb 2017 04:02 AM
coolrainbow is the only smart one here.
You guys are seriously stupid if you don't understand what he's saying.
Report Abuse
Disillusions is not online. Disillusions
Joined: 10 Jul 2011
Total Posts: 6365
18 Feb 2017 04:07 AM
local spawns = workspace.First.FirstLevelSpawns:GetChildren() for i, # in pairs(game.Players:GetPlayers()) do if ########### ## nil then ############################################################ end end will spawn characters in each spawn, then when spawns run out spawn them from first spawn again
Report Abuse
Disillusions is not online. Disillusions
Joined: 10 Jul 2011
Total Posts: 6365
18 Feb 2017 04:09 AM
local spawns = workspace.First.FirstLevelSpawns:GetChildren() for i, player in pairs(game.Players:GetPlayers()) do if player.Character ## nil then player.Character:MoveTo(spawn[math.max(1,i % #################### end end
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
18 Feb 2017 04:10 AM
... v.Character:MoveTo(spawns[i%#spawns+1].Position)

@Ozzy that's a very bad way to randomize a table.
There's a simpler and more efficient way:
for idx = 1, #tb/2 do
local idx2 = math.random(len)
tb[idx], tb[idx2] = tb[idx2], tb[idx]
end
Report Abuse
Disillusions is not online. Disillusions
Joined: 10 Jul 2011
Total Posts: 6365
18 Feb 2017 04:11 AM
thats what i was trying to type

you have let me down preview


Report Abuse
OzzyFin is not online. OzzyFin
Joined: 07 Jun 2011
Total Posts: 3600
18 Feb 2017 05:19 AM
yeah I totally forgot about how sorting algorithms work

It'd possibly get into an infinite loop if lua didn't error before that, right?
Report Abuse
OzzyFin is not online. OzzyFin
Joined: 07 Jun 2011
Total Posts: 3600
18 Feb 2017 05:22 AM
well not infinite, the odds of math.random generating such a pattern aren't too good for that
more like a long loop that'd take way longer than it should to do the task
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
18 Feb 2017 05:35 AM
Yup.
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