Fixing your code with a roblox task defer script
Using a roblox task defer script is the best way to handle those weird timing issues that pop up when you're coding a game. If you've spent any time in Roblox Studio, you know that sometimes things just don't happen in the order you expect. You might try to reference a player's UI right as they join, only to get an error because the UI hasn't actually finished loading yet. That's where deferring comes in to save your sanity. ...