This is an easy fix. First, you'll want to use an event for whenever something is added to the workspace. In this case it'll be your player. This could be any object though, so we'll need to confirm that this is in fact a player. We'll want to check if it has a humanoid inside of it. Here is it with your script inside of the event.
1 | game.Workspace.ChildAdded.connect( function (child) |
2 | if child:FindFirstChild( 'Humanoid' ) then |
3 | local animation = Instance.new( "Animation" ) |
6 | local animTrack = Humanoid:LoadAnimation(animation) |
If you wanted it for just YOU specificaly, just do a simple check of the player's nbame. Like this:
01 | game.Workspace.ChildAdded.connect( function (child) |
02 | if child:FindFirstChild( 'Humanoid' ) then |
03 | if child.Name = = "NoahJordan21" then |
04 | local animation = Instance.new( "Animation" ) |
07 | local animTrack = Humanoid:LoadAnimation(animation) |
i just want to add, you haven't identified what Humanoid is in local aimtrack. If you haven't done that elsewhere in the script, you could just do:
1 | local Humanoid = child.Humanoid |
Just make sure you put that in the event.