So I'm doing stuff with jumping mechanics as seen here:
UserInput = game:GetService("UserInputService") UserInput.InputBegan:Connect(function(KeyDown, gameProcessed) if not gameProcessed then if KeyDown.KeyCode == Enum.KeyCode.Space then wait(0.2) game.Workspace.Gravity = 88 wait(2) game.Workspace.Gravity = 110 end end end)
When they hit the Space bar it will do something, but I want it where the Gravity will be 88 until the player hits the ground, once they hit the ground it will reset it to 110. I know I would need to use the until statement or something, but I just don't know how to detect if a player hits the ground or not.
[P.S, READ I'm also not talking about terrain material, I'm talking about parts. I'm using parts as my terrain.]
Place all your parts that make up your terrain as a grouped model and name the model as TerrainParts
. If so, then:
local terrain = workspace.TerrainParts:GetChildren() for _, part in pairs(terrain) do part.Touched:Connect(function(hit) local humanoid = hit.Parent:FindFirstChild("Humanoid") if humanoid then workspace.Gravity = 110 end end) end
Now that we have compiled the script that detects when the character has touched the ground, we must figure out how to incorporate into your script:
UserInput = game:GetService("UserInputService") UserInput.InputBegan:Connect(function(KeyDown, gameProcessed) if not gameProcessed then if KeyDown.KeyCode == Enum.KeyCode.Space then wait(0.2) game.Workspace.Gravity = 88 local terrain = workspace.TerrainParts:GetChildren() for _, part in pairs(terrain) do part.Touched:Connect(function(hit) local humanoid = hit.Parent:FindFirstChild("Humanoid") if humanoid then workspace.Gravity = 110 end end) end end end end)