|
| 15 Jul 2015 08:19 AM |
so i want to get all players characters, but when i try to name a variable players with the value being game.Players:GetPlayers() instead of some for loops it tells me that Character is a nil value
local players = game.Players:GetPlayers() local run = true local Message = workspace.LobbyMessage local RoundEnd = true
function blah() end
while wait() do local AlivePlayers = 0 wait(5) if run then run = false Message.Text = "Preparing..." -- we'll get fancy with GUIs later local maps = game.ReplicatedStorage.Maps:GetChildren() Map = maps[math.random(1,#maps)] local NewMap = Map:Clone() NewMap.Parent = workspace wait(1) Message.Text = "" while true do for i, players in pairs(game.Players:GetPlayers()) do AlivePlayers = game.Players.NumPlayers players.Character.Humanoid.Died:connect(function() AlivePlayers = AlivePlayers - 1 end) end for i, players in pairs(game.Players:GetPlayers()) do players.Character.Torso.CFrame = CFrame.new(NewMap.Start.Position.X,NewMap.Start.Position.Y+12,NewMap.Start.Position.Z) end players.Character.Humanoid.WalkSpeed = 0 wait(2) Message.Text = "GO" players.Character.Humanoid.WalkSpeed = 50 wait(.3) Message.Text = "" end if RoundEnd == true then NewMap.End.Touched:connect(function(It) run = true local spawn = workspace.SpawnLocation local player = game.Players:GetPlayerFromCharacter(It.Parent) print("waiting") for i,players in pairs(game.Players:GetPlayers()) do players.Character.Torso.CFrame = CFrame.new(spawn.Position.X+i,spawn.Position.Y+12,spawn.Position.Z+i) Message.Text = (player.Name.." Has won") players.Character.Humanoid.WalkSpeed = 16 player.leaderstats.Coins.Value = player.leaderstats.Coins.Value+50 NewMap:Destroy() wait(3) Message.Text = ("") wait(5) end end) spawn(function() repeat wait() until AlivePlayers <= 0 run = false Message.Text = "Everyone died... gg" wait(3) Message.Text = "" NewMap:Destroy() run = true end) end end end
<3 cats <3 |
|
|
| Report Abuse |
|
|
|
| 15 Jul 2015 08:21 AM |
Okay, you should do this
local players = game.Players:GetChildren()
for _, player in pairs(players) do local char = player.Character if char then
end end |
|
|
| Report Abuse |
|
|
|
| 15 Jul 2015 08:24 AM |
it errors right here and if i do it for each player then the message happens for each player
players.Character.Humanoid.WalkSpeed = 0 wait(2) Message.Text = "GO" players.Character.Humanoid.WalkSpeed = 50 wait(.3) Message.Text = ""
<3 cats <3 |
|
|
| Report Abuse |
|
|
|
| 15 Jul 2015 08:30 AM |
so i CANT do a for loop there
<3 cats <3 |
|
|
| Report Abuse |
|
|
| |
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 15 Jul 2015 09:55 AM |
I felt that I was obliged to offer my own solution.
local replicator = _G.Valkyrie:GenerateWrapper(true); replicator.mt.__index = replicator(function(t,k) if type(t) == 'table' then local r = {}; for n,v in next,t do r[n] = v[k]; end return r; end return t[k]; end) replicator.mt.__newindex = replicator(function(t,k,v) if type(t) == 'table' then for _,u in next,t do u[k] = v; end return nil; end t[k] = v; end)
Usage: replicator(game.Players:GetChildren()).Character.Humanoid.WalkSpeed = 16; |
|
|
| Report Abuse |
|
|
|
| 15 Jul 2015 07:04 PM |
what does 'replicator' do exactly?
<3 cats <3 |
|
|
| Report Abuse |
|
|
| |
|
|
| 15 Jul 2015 07:42 PM |
well actually what does GenerateWrapper do?
<3 cats <3 |
|
|
| Report Abuse |
|
|
| |
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 15 Jul 2015 10:52 PM |
http://www.roblox.com/PlayersDeadAliveScript-item?id=255028728
"Talk is cheap. Show me the code." - Linus Torvalds |
|
|
| Report Abuse |
|
|
|
| 16 Jul 2015 12:16 AM |
im not looking for if the players are alive
<3 cats <3 |
|
|
| Report Abuse |
|
|
|
| 16 Jul 2015 01:17 AM |
so what does replicate do?
<3 cats <3 |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 16 Jul 2015 01:59 AM |
| It's an object that makes it so that if you're too stupid to know how to engineer your for loops, it does it for you. |
|
|
| Report Abuse |
|
|
|
| 16 Jul 2015 04:39 AM |
so could you explain a little further how that was put together? like why is Valkyrie in there and what does _G do?
<3 cats <3 |
|
|
| Report Abuse |
|
|
| |
|
Jradi
|
  |
| Joined: 15 Aug 2012 |
| Total Posts: 10015 |
|
|
| 16 Jul 2015 07:25 AM |
You can't get the characters of ALL players just because you set a variable of all the players (in a table).
for i,v in pairs(Players) do -- insert what you want to do to EACH character end
=[ Chairman of Arlite Core |
|
|
| Report Abuse |
|
|