Taking damage when going up

I am making this game where you climb some stairs, and after reaching a certain height, you start taking damage the further you go up, however I am not so sure how I would create a script where you would take damage when ascending ingame.

Hi,
What you could do, is checking the Position.Y of the player character’s humanoidRootPart. If they’re above Ydamagelayer, they start to take damage. You can then fiddle around with, that they take more damage the further up they are.

local YDamageLayer = 20
while task.wait(1) do
	for _, Player in pairs(game.Players:GetPlayers()) do
		local Character = Player.Character
		if not Character then continue end
		local CorePart = Character:FindFirstChild("HumanoidRootPart")
		local Humanoid = Character:FindFirstChildOfClass("Humanoid")
		if not CorePart or not Humanoid then continue end
		if CorePart.Position.Y < YDamageLayer then continue end
		local DistanceAbove = (CorePart.Position.Y - YDamageLayer).Magnitude
		Humanoid:TakeDamage(1 + (DistanceAbove/10)) -- They take 1 damage as base damage, then we take 10% of the studs they are above YDamageLayer and add that to the damage aswell.
	end
end