try adding this script in StarterPlayer > StarterCharacterScripts
spawn(function()
local Char = script.Parent
local Hum = Char:FindFirstChild("Humanoid")
local HRP = Char:FindFirstChild("HumanoidRootPart")
while wait(1) do
if Hum ~= nil then
if HRP ~= nil then
local CurPos = HRP.Position
if CurPos.Y < 100 then
Hum:TakeDamage(2)
elseif CurPos.Y >= 100 then
Hum:TakeDamage(5)
end
end
end
end
end)
It kinda works, trying to make the player take damage only once he goes up though, so if he goes down or stays the same he doesn’t take damage but if he climbs up, he does.
So, basically the lower the player goes, the more damage they take every second?
This is easy to do. All you need to do is check the players position on the Y axis. If that position’s Y value is under 50 studs then damage the player
Example;
Char = script.Parent
while true do
wait(1)
if Char.HumanoidRootPart.Position.Y <= -50 then
Char.Humanoid:TakeDamage(2)
elseif Char.HumanoidRootPart.Position.Y <= 100 then
Char.Humanoid:TakeDamage(5)
end
end
Tossed this together, should work, haven’t tested it though. The cooldown is to make the damage per second.
local lastHeightCache = {}
game:GetService("Players").PlayerAdded:Connect(function(player)
local playerId = player.UserId
local character = player.Character or player.CharacterAdded:wait()
local humanoid = character.Humanoid
local head = character.Head
lastHeightCache[playerId] = head.Position.Y
head:GetPropertyChangedSignal("Position"):Connect(function()
local yPos = head.Position.Y
-- If they've not moved up:
if yPos <= lastHeightCache[playerId] then
return -- Escape function
end
-- If they have moved up:
if cooldown == true then -- If a second has passed since last damage, start a cooldown
coroutine.wrap(function()
cooldown = false
wait(1)
cooldown = true
end)()
elseif yPos <= 50 then
humanoid:TakeDamage(2)
elseif yPos <= 100 then
humanoid:TakeDamage(5)
end
lastHeightCache[playerId] = yPos -- Update the last height
end)
end)