This is a server script located in ServerScriptServices
The problem with this is that whenevever the player respawns “stamina changing” will print twice as much because the old changed event still exists.
A solution would be to not put it inside the charloaded Event and instead have local character = player.Character or player.CharacterAdded:Wait()
but when I reset and print(character.Parent) it prints nil
I formatted it like so because the function passed into the :Connect() function is not yet aware that the c2 variable exists, because it is currently being assigned. Assigning it to nil first assures that the variable exists. It is the equivalent to
No. The semi-colon is negligible (meaning that it’s not even required, I just put it there to look cleaner), however the comma means you’re assigning two variables.
Again, the semi-colon doesn’t do anything but make the code cleaner. You could substitute it for a space of course, but a semi-colon is usually my go-to. Any code can be put in one line, however you should be wary that not everything should go in one line. Always keep it consistent.
The second one technically is shorter but it yields and yielding typically is an undesirable effect as any code after it will not be run until the character dies (which is when the code will stop yielding).
1st connects Humanoid.Died, after the event is triggered it disconnects both of the connections.
And 2nd yields until the player dies then disconnects the changed connection.
In this case, you could replace the “died” event (starting from character) with player.CharacterRemoving. This will fire whenever the character is being removed from the game,