Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

Why doesn't this code work?*Announces survivors in hint?*

Asked by 10 years ago
function survive_ann()
Survivors = {}
players = game.Players:GetPlayers()
for _,v in pairs(players) do
if(v.Character) then
    v.Character:MoveTo(Vector3.new(243,1.5,-225.4))
    wait(15)
   table.insert(Survivors,v.Name)
    Finished = Instance.new("Message")
    Finished.Parent = game.Workspace
    Finished.Text = "The following have survived"..table.concat(Survivors,',')

It does not work. I have no idea why. It is supposed to add players to a table. But it doesn't do that and it doesn't even announce the message :(

Also: Q#2: for players = game.Players:GetPlayers() Would it get the players and keep those names and not add anymore names or would it keep adding names to the variable? That's all I want to know for this question #2. Why not work?

1 answer

Log in to vote
0
Answered by
MrFlimsy 345 Moderation Voter
10 years ago

You need ends to close your for loop and if statement.

function survive_ann()
Survivors = {}
players = game.Players:GetPlayers()
for _,v in pairs(players) do
    if(v.Character) then
        v.Character:MoveTo(Vector3.new(243,1.5,-225.4))
        table.insert(Survivors,v.Name)
    end
end
wait(15) --I moved this, otherwise it would run once for every player.
Finished = Instance.new("Message")
Finished.Parent = game.Workspace
Finished.Text = "The following have survived"..table.concat(Survivors,',')
0
Show me how you would do it, because even if i did that - it still would not work. Overpride 0 — 10y
0
Have you tried it? The reason your code wasn't working is because all blocks of code need an 'end' statement to close them off. MrFlimsy 345 — 10y
0
Yes I tried it before, I believe - can you just show me how you'd do it? Also if I didn't have an end function the script wouldn't even run so yeah. Overpride 0 — 10y
0
I don't quite understand what you mean by 'how I would do it'. Could you elaborate further? MrFlimsy 345 — 10y
0
Ugh, nevermind, I'll experiment and post another q' up in a bit maybe. Overpride 0 — 10y
Ad

Answer this question