Superhero Landing

Okay so I did everything you told me to apart from creating an Animation inside the script and now I’m getting the error: Play is not a valid member of Animation “Animation”
But it only gives me the error when I jump and not when I land

No, you need to load the animation on the player for it to play. You can’t call Play on an animation, that’s my mistake.
Instead of this:

Landing:Play();

Do this:

local animTrack = char.Humanoid:LoadAnimation(Landing);
animTrack:Play();

Oh okay thanks!
The animation works but it’s more of a jump animation instead of a landing.
You know how like when a superhero does a super cool hero landing they get on their knees and then rise up? That’s basically what the animation is, it starts on the knees and rises up, so instead of the animation starting mid air, I want it to start when it hits the ground.

I already have a jump animation, that’s not a problem. The problem is the animation starting when the player hits the ground.

And the animation works but the explosion still doesn’t

So, to clarify, the animation works, but the explosion doesn’t get created? Or does it just get created on the client side?

Yeah, there’s no explosion at all

Try parenting the explosion to the workspace. Add a line that says this:

explosion.Parent = game.Workspace;

Note that, even if the explosion shows up for the player who landed, it won’t show up for other players. For that, you need to learn about remote events. Again, I recommend AlvinBlox or TheDevKing as two good resources on YouTube, they have some great tutorials.

1 Like

Thanks, the explosion works and I’ll keep in mind to check out AlvinBlox and TheDevKing.

I don’t wanna sound ungrateful but I want the explosion and animation to occur once the player has hit the ground, not when they jump. Although now that the explosion happens when the player jumps, I can create another effect to make my double jump look cooler.

Oh, there’s a simple fix for that.

Change the Jumping line to this:

humanoid.Jumping:Connect(function(isActive))

And then, after that, change the tostring line to this:

(tostring(char.Humanoid.FloorMaterial) ~= "Air") and (isActive == false)

Let me know if this works.

When I tried to change those lines it had a lot of errors so I’ll just give you the lines because I don’t know what to remove to make it work

char.Humanoid.Jumping:Connect(function() 
	if (tostring(char.Humanoid.FloorMaterial) ~= "Air") then

Change that to this:

char.Humanoid.Jumping:Connect(function(isActive)
    if ((tostring(char.Humanoid.FloorMaterial) ~= "Air") and (isActive == false)) then

It didn’t really change anything, it still plays the animation and explosion effect but it only does it when I jump, not land.

I recently replied to a comment related to this topic.

@ThunderFrost0001 gave a snippet of code based on when you jump and land:

 Humanoid.StateChanged:Connect(function(PreviousState, NewState)
 	if NewState == Enum.HumanoidStateType.Freefall then
		-- what to do when it starts falling
 	elseif NewState == Enum.HumanoidStateType.Landed then
 		-- what to do when it landed
           (In your case play landed animation)
 	end
 end 

I also commented about this in the use of the formula h=1/2gt^2 this will let you get the height they are at when they hit the ground.

You can read that here: How to detect when a player has fell a certain amount of studs Mid-Air? - #4 by DouglasRastelli

Okay, so combining our code with jack’s, it’ll look something like this:

local Humanoid = char.Humanoid;
Humanoid.StateChanged:Connect(function(PreviousState, NewState)
    if NewState == Enum.HumanoidStateType.Landed then
        local animTrack = Humanoid:LoadAnimation(Landing);
 		animTrack:Play();
       	local explosion = Instance.new("Explosion"); -- This creates the explosion
        explosion.Position = char.UpperTorso.Position; -- This positions the explosion at the character's torso
        explosion.BlastRadius = 0; -- Assuming you don't want the explosion to do any damage, include this line. Otherwise, the explosion will kill the player.
        explosion.Parent = game.Workspace;
        -- explosion will only be visible for the client who lands; use remote events to make the explosion on the server side.
 	end
 end 

I wasn’t aware of StateChanged, but it seems like that’s a much better solution.

1 Like

This is it! It works! The only thing missing is the explosion but that can be fixed by making the explosion’s parent workspace.

I really don’t want to bother you any more than I already did but if you could just make it so that the player can’t move or jump (Or just freeze the player, if that’s possible) while the animation is playing that would be very helpful thanks!

Edited the code to include that. If you could mark that as the solution, I’d appreciate it :slight_smile:

Thanks so much! What about that immobility part? If not then it’s no problem at all!

Again thank you for all your help… This was a really complicated script and you took 3 hours out of your day to help me fix it. I can’t thank you enough.
Also, I learned so much from this, so thanks for that as well.

No problem, man. What do you mean by immobility part?

Well I meant if there was a way to possibly make the player immobile while the animation is playing, or to freeze them completely without breaking the script that would also be helpful, if it’s not possible, then it’s fine I’ll figure out a way. I don’t wanna waste any more of your time.

If you mean making the player immobile, you could add this after the explosion code:

Humanoid.WalkSpeed = 0;
wait(Landing.Length);
Humanoid.WalkSpeed = 16;

Making the whole code look like this:

local Humanoid = char.Humanoid;
Humanoid.StateChanged:Connect(function(PreviousState, NewState)
    if NewState == Enum.HumanoidStateType.Landed then
        local animTrack = Humanoid:LoadAnimation(Landing);
 		animTrack:Play();
       	local explosion = Instance.new("Explosion"); -- This creates the explosion
        explosion.Position = char.UpperTorso.Position; -- This positions the explosion at the character's torso
        explosion.BlastRadius = 0; -- Assuming you don't want the explosion to do any damage, include this line. Otherwise, the explosion will kill the player.
        explosion.Parent = game.Workspace;
        -- explosion will only be visible for the client who lands; use remote events to make the explosion on the server side.
        Humanoid.WalkSpeed = 0;
        wait(Landing.Length);
        Humanoid.WalkSpeed = 16;
 	end
 end 
1 Like

I also meant like unable to jump as well, but then I could just do

Humanoid.JumpPower = 0;
wait(Landing.Length)
Humanoid.JumpPower = whatever the default jumppower is

Right?