Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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,',')

5 comments

0

Show me how you would do it, because even if i did that - it still would not work.

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.

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.

0

I don't quite understand what you mean by 'how I would do it'. Could you elaborate further?

0

Ugh, nevermind, I'll experiment and post another q' up in a bit maybe.

This discussion is preserved as it was. New answers, comments, and votes are closed.