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

How to let a script know when a new player is added?

Asked by 5 years ago

So I have this script here... script.Parent.Text being a text box where a players name is located.

    local Action = game.Players:GetPlayers("Players")


  for i = 1,#Action do
Action[i].Chatted:connect(function(Message)
    if Action[i].Name == script.Parent.Text then
        if Message == ';command' then

--command script here


        end -- ends if message statement

    end -- ends if Action[i] statement

  end) -- ends chatted function
end -- ends for statement

works perfectly except when ever a new player joins the game this script won't recognize their chat. I have tried adding this above the script

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
    Action = game.Players:GetPlayers("Players")
    end)
end)

but this did not work sadly... been trying to figure this out for weeks lol

2
GetPlayers takes no arguments, so might as well remove the string "Players" since it serves no purpose. And why does the local script hook a Chatted event for *other* players? User#24403 69 — 5y

Answer this question