Superhero Landing

So my topic here is a superhero landing that plays an animation when the player hits the ground from a certain high, kinda like how if you do a jump from high distance you get the landing sound, but if you do a regular jump, you don’t get the sound. Basically…

  1. What do you want to achieve? I want to make a script that makes the player do an animation then they hit the ground (A superhero landing) and an effect happens when they hit the ground, kinda like the ground breaking, but.

  2. What is the issue? The issue is that I’m not sure how to do it. I’m very lost.

  3. What solutions have you tried so far? I’ve tried to write a couple scripts but I just can’t seem to get it right. Now that I think about it, it’ pretty complicated especially for my scripting skills.

local Landing = Instance.new("Animation")
Landing.AnimationId = "rbxassetid://6303328114"
local Landed = game.Players.PlayerAdded:Connect(function(plr) 
	plr.CharacterAdded:Connect(function(char) --This is to get the player
		if	char.Humanoid.FloorMaterial == Plastic then --When the player touches the ground
			Landing:Play() --Play the Superhero Landing
			game.Instance.ChildAdded:Connect(function(Instance.new("Explosion")) --Create an explosion when you hit the ground
				
			end)
		end
	end)
end)

So as you can probably tell, I’m not the best scripter but I created this script and I tried several alternatives and I can’t seem to get it working they way I want it to.
Anyway, thanks for taking the time to read this hopefully this problem can be solved.
If the explosion needs to be in a separate script that’s fine.

1 Like

So, what your code is doing right now is creating a listener for the character spawning. When the character spawns, their floor material is checked once and only once. To fix this first issue, I would connect a function to the Humanoid.Jumping event. The following code would go in plr.CharacterAdded:

char.Humanoid.Jumping:Connect(function()
    if char.Humanoid.FloorMaterial == Plastic then
        Landing: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.
    end
end)

Let me know if this works or if you have any questions.

1 Like

It didn’t work. It says it wants me to cloes the ‘(’ for

char.Humanoid.Jumping:Connect(function()

Also the game is in R6 so I’ll change the UpperTorso to Torso

1 Like

Oh, my bad. The code should have a closed parenthesis at the end. I edited the comment and updated the code. And yes, if the game is in R6, you should use a regular Torso. Let me know if the issue persists.

1 Like

So it was giving me an error telling me to add two end)'s and that’s what I did and it was fine. Now it’s saying “Unknown Global ‘Plastic’”.
Do I like make it Identify it with a “local”? If so what would It be equal to?
Also, it doesn’t exactly have to be plastic, I just need it to play the animation and explosion when it hits the floor from a high distance.
The explosion is kinda irrelevant so if that’s making the script harder to fix then it can be removed, I’ll find a way to add it separately.

1 Like

So there’s a couple of issues. First off, in this context, Plastic is a variable that you haven’t defined. If you wanted to check if it were plastic, you would have to use a string. The second issue is that Humanoid.FloorMaterial doesn’t return a string; it returns a FloorMaterial. This can be addressed by using tostring() on it. The last problem is that Plastic is only one material. What you want to do is see if it is any material. Humanoid.FloorMaterial returns Air if there’s no material; therefore, instead of checking if the player hits Plastic, you should check if the player doesn’t hit air. Here’s the code, with all the relevant corrections:

char.Humanoid.Jumping:Connect(function()
    if (tostring(char.Humanoid.FloorMaterial) ~= "Air") then
        Landing: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.
    end
end)

1 Like

I probably should have said this sooner, but I still have the

local Landing = Instance.new("Animation")
Landing.AnimationId = "rbxassetid://6303328114"
local Landed = game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)

Above the

Do I do something about that or leave it? Or maybe do I put an Animation inside of the script and set Landing to that?

And It keeps telling me to add “end)” twice after the

    end
end)

Ok, the format got all messed up on your reply. To clear up any confusion, here is all the code put together:

local Landing = Instance.new("Animation")
Landing.AnimationId = "rbxassetid://6303328114"
local Landed = game.Players.PlayerAdded:Connect(function(plr) 
	plr.CharacterAdded:Connect(function(char) --This is to get the player
		char.Humanoid.Jumping:Connect(function()
    		if (tostring(char.Humanoid.FloorMaterial) ~= "Air") then
        		Landing: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.
    		end
		end)
	end)
end)

This is the first time I’m getting an error message,
It’s saying Play is not a valid member of Animation “Animation” For the line Landing:Play();

Oh also this is a regular Script inside Workspace. That might possibly be a reason why it’s not going so well. Must I change it to a local script and/or put the Script into another parent in the explorer?

Okay, I am just now realizing that this is on a server script. Yes, this should be done in a local script. Additionally, you can get rid of the PlayerAdded event and player character added event. Instead, you could do something like this:

local plr = game:GetService("Players").LocalPlayer; --since it's in a localscript, you can use LocalPlayer to get the player
local char = plr.Character;
char.Humanoid.Jumping:Connect(function() -- code in here will run every time the player jumps or lands
    if (tostring(char.Humanoid.FloorMaterial) ~= "Air") then
        Landing: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.
    end
end)


Let me know if you have any questions.

1 Like

Also, another thing I oversaw- you should create the explosion on the serverside using RemoteEvents. Since this script is clientside, the explosion will only be created for the player who lands, and will not be visible to everyone.

I have 3 questions.
Is this LocalScript supposed to be in a place other than Workspace or is it fine in workspace?
Also would it matter if I change the animation’s priority? And would it make a difference if I create an Animation inside of the LocalScript and have the animation play from that?

Also I have a double jump script so the player also kinda plays an animation when they’re jumping. If it makes it easier to have the animation only play when the player hits the ground from a certain height then that will do.

I prefer the explosion to be seen by all players because it is supposed to be a substitute for like a ground breaking effect, since I don’t know how to do that yet, the explosion will have to do for now.

I would put the localscript in StarterCharacterScripts, since it’ll guarantee that the player’s character exists at the script’s runtime. The animation’s priority should be set to the highest priority (action I believe), since it would need to override any other animations that may occur when you fall. Yes, you could create the Animation in the LocalScript, so long as you load it onto the player’s Humanoid.

To your second comment, it would be far more complex to have the animation only occur after falling from a certain height, though it’s certainly doable.

As far as the explosion goes, I recommend looking up tutorials on Remote Events and Filtering Enabled; it’s too complex for me to explain concisely in this post, and there’s plenty of tutorials on the subject. DevKing has some good tutorials.

Other than that, did the code function as intended?

It did not. But I’ll try these, except, the load it onto the player’s humanoid part sounds hard so I’ll leave the animation loading the way it is.

Although I might have to recreate the animation because I think I deleted the dummy that I created it on…

Edit: Okay so nevermind… I’m an idiot. The animation was an R15 animation…

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