✓ Accepted answer
Yielding
That function yields. It's annoying, we all hate it, but it yields. That means that the first Player will join by the time that the connection is ready. You have 2 options in this case, which is either lazy loading or cleaning up.
Cleaning up
No, that's not what it's really called
In this case, you are going to do to every player already in the game what you would have done when they joined. Valkyrie does this because there's not really a practical use for lazy-loading in its use-case.
local function PlayerAdded(p)
end;
game.Players.PlayerAdded:connect(PlayerAdded);
for k,v in next, game.Players:GetPlayers() do
spawn(function()
PlayerAdded(v);
end);
end
Lazy-loading
Deferred loading if it makes you happier
In this case, you actually run all of your code on the first time that the event happens. It takes a little bit of setting up on your end, because you have to decide what to lazy load and how.
local Board, OtherVariablesYouNeed;
local _init = false;
local function Lazy()
local Trello = require(TrelloAPI);
Board = Trello:GetBoardID("Test");
_init = true;
end;
game.Players.PlayerAdded:connect(function(p)
if not _init then Lazy() end;
end);
4 comments
Try putting the GetBoardId function in its own thread (coroutine or spawn function)
yet i need that to input player names... i could remove it t o solve it,but it would not help get the end results which simply prints the player name on trello when user is joined
Put the Trello and Board Variable inside of the Function maybe that would help.
the function does not work with the variables...