Really simple question, How can I make it wait until the player is on the ground?

Hey! Question, How can I set it so it waits for the player to be on the ground?
Here’s my current script:

repeat wait() until enemyplayer.Humanoid.FloorMaterial == Enum.Material.SmoothPlastic
local VFX = game.ReplicatedStorage.Game_VFX.VFX_GroundPound:Clone()
VFX.Parent = workspace.Custom_Workspace[player.Name.."_Workspace"]
VFX:SetPrimaryPartCFrame(enemyplayer.HumanoidRootPart.CFrame)
VFX.Main.Disabled = false
game:GetService("Debris"):AddItem(VFX,2)

local VFX = game.ReplicatedStorage.Game_VFX.VFX_Wind:Clone()
VFX.Parent = workspace.Custom_Workspace[player.Name.."_Workspace"]
VFX:SetPrimaryPartCFrame(enemyplayer.HumanoidRootPart.CFrame)
VFX.Main.Disabled = false
game:GetService("Debris"):AddItem(VFX,2)

This is where it isn’t waiting:

repeat wait() until enemyplayer.Humanoid.FloorMaterial == Enum.Material.SmoothPlastic

Thanks!

1 Like

You could try and wait until the Humanoid exits the freefalling state

Could you reference the Baseplate and use a :Touched event?

The thing is, It needs to be in a repeat line xd

@sparklenico20 - How would I accomplish this?

Are you looking to wait() until the player lands on any object or is there a specific ground area you need them to touch down on?

1 Like

So, you don’t want the script to stop is what you mean?

I just want the script to pause until the player lands. :slight_smile:

Nope! Just whenever they touch the ground!

You can replace the repeat with this

If Humanoid:GetState() == Enum.HumanoidStateType.FreeFall then
Humanoid.StateChanged:Wait()
end

Okay! I actually just figured it out, Thank you! I’ll try this aswell to see which one works better! Thank you for helping me!

1 Like

No problem, Glad to help! Just ask more questions if u have any

1 Like

Here’s a solution that should be somewhat more accurate (but more complex) than the ones above, given that humanoid states can be volatile

local rootPart = enemyPlayer.HumanoidRootPart
local rootPartHeight = enemyPlayer.Humanoid.HipHeight + rootPart.Size.Y / 2; -- calculate height of the root part from the bottom of the character

local rayParams = RaycastParams.new()
rayParams.FilterDescendantsInstances = { enemyPlayer }
rayParams.FilterType = Enum.RaycastFilterType.Blacklist

repeat
	local raycast = workspace:Raycast(rootPart.Position, Vector3.new(0, -9000, 0), rayParams)
	local distance;
	
	if raycast then
		distance = (rootPart.Position - raycast.Position).Magnitude
	end
	
	wait()
until distance and distance <= rootPartHeight

this casts a ray downwards from the HumanoidRootParts position and checks to how far away we are from the closest ground. if our distance is that of our rootpart-height then the repeat loop exits

If you haven’t yet looked into learning raycasting yet I urge you to try it as soon as you can

2 Likes