Superhero Landing

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?

I believe so. I’ve never personally used JumpPower, but give it a shot and let me know what happens.

Default JumpPower is 50 by the way. Putting all the code together for a clean solution (for anyone else who stumbles upon this thread):

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;
        Humanoid.JumpPower = 0;
        wait(Landing.Length);
        Humanoid.JumpPower = 50;
        Humanoid.WalkSpeed = 16;
 	end
 end 
1 Like

Small problem… It doesn’t let me jump at all. Even when the animation is over.
It says Length is not a valid member of Animation “Animation”
If I delete length and just have

wait(Landing)

It says
Walkspeed is not a valid member of Humanoid “Workspace.ZIMOPlayzRBLX.Humanoid”

Then I put the actual length of the animation (1.10) and it says the same thing
Walkspeed is not a valid member of Humanoid “Workspace.ZIMOPlayzRBLX.Humanoid”

1 Like

I just noticed a few issues.

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;
        Humanoid.JumpPower = 0;
        wait(animTrack.Length);
        Humanoid.JumpPower = 50;
        Humanoid.WalkSpeed = 16;
 	end
 end 

Make sure that WalkSpeed is spelt with a capital “s” on the speed. That happens a lot of the time. I also changed it from Landing.Length to animTrack.Length, since Length is a property of an AnimTrack, not an animation. If this solution works for you, be sure to mark it as the solution so other people can come in and see it if need be.

3 Likes

Perfect! Thanks so Much! Took about 4 hours but it was totally worth it for me. Now I just have to make it so it only works when the player has fallen from a certain distance.

I honestly can’t thank you enough. This was wayy too complicated for someone of my level but I have learned a lot.
I’m so grateful for this, like, beyond grateful. Sorry for wasting your time but it was beneficial to me, trust me.

1 Like

Hey, no problem. The falling for a certain time isn’t too hard; modifying Jack’s code from earlier:

local Humanoid = char.Humanoid;
local fallingTime = -1; -- will be initialized later; the time when the falling started
Humanoid.StateChanged:Connect(function(PreviousState, NewState)
 	if NewState == Enum.HumanoidStateType.Freefall then
            if Humanoid.StateType == Enum.HumanoidStateType.Freefall then
                fallingTime = tick(); -- tick() gets the current time; we can subtract the time they started falling from the time they land to see how long they fell
            end

 	elseif NewState == Enum.HumanoidStateType.Landed then
 		if (tick() - fallingTime > 10) then --where 10 is the amount of seconds you want to fall for a superhero landing
 		    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
 end 
2 Likes