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.
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.
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.
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!
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.
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.
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
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
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.
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.
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