My fall damage script is not breaking trough the loop

My script is not printing anything at all, I passed out crying 3 times already and I cannot find a solution anywhere.

Here is what I have now:

  • The script you told me
  • The changes to the gliding script adapted to the new script
  • This code that made me cry and pass out 3 times (fall damage script):
-- Variables
local damageHeight = 14 -- The height at which the player will start getting damaged at
local lethalHeight = 26 -- The height at which the player will get killed

game:GetService("Players").PlayerAdded:Connect(function (plr)
	plr.CharacterAdded:Connect(function (char)

		local root = char:WaitForChild("HumanoidRootPart")
		local humanoid = char:WaitForChild("Humanoid")

		if humanoid and root then
			local gliding = plr:WaitForChild("Gliding")
			
			if gliding.Value == true then return end
			local headHeight

			wait(3) -- Prevent the player from dying on spawn
			humanoid.FreeFalling:Connect(function (state)
				if state then
					headHeight = root.Position.Y
				elseif not state and headHeight ~= nil then
					pcall(function ()

						local fell = headHeight - root.Position.Y

						if fell >= lethalHeight then
							humanoid.Health = 0
						elseif fell >= damageHeight then
							humanoid.Health = humanoid.Health - math.floor(fell)
						end
					end)
				end
			end)
		end
	end)
end)
  • And my electricity at home keeping on going away

Maybe try removing this space here. Just small changes can make a difference.

1 Like

I’m not familiar with this API. Is this something in Lua? Try changing it to :Destroy()

1 Like

Nope, nothing changed.β€β€β€Ž β€Žβ€β€β€Ž β€Ž

Hmm. Not at the moment, but I’ll try loading this into studio and see what happens.

1 Like

Remember to use my gliding script too, my gliding script might have some issue

1 Like

In your if statement that checks if the gliding boolvalue equals true, maybe you can delete the return and try a repeat wait until function that repeats a wait() until the gliding value equals false, then move on with the rest of the code.

I know that’s probably what you’re already doing here, but maybe change up your approach.

1 Like

I am gonna try someting like that

Nope, still cannot figure out anything.

Can you send your code and where you put the repeat wait until please. Send me your completely updated code for both the gliding script and the fall damage script. That way I will know where you are in both of them.

Here it goes.

-- Variables
local damageHeight = 14 -- The height at which the player will start getting damaged at
local lethalHeight = 26 -- The height at which the player will get killed



game:GetService("Players").PlayerAdded:Connect(function (plr)
	plr.CharacterAdded:Connect(function (char)

		local root = char:WaitForChild("HumanoidRootPart")
		local humanoid = char:WaitForChild("Humanoid")

		if humanoid and root then
			local gliding = plr:WaitForChild("Gliding")
			repeat wait() until gliding.Value == false
			local headHeight

			wait(3) -- Prevent the player from dying on spawn
			humanoid.StateChanged:Connect(function(state)
				if state == Enum.HumanoidStateType.Freefall or state == Enum.HumanoidStateType.FallingDown then 
					while state ~= Enum.HumanoidStateType.Freefall or state ~= Enum.HumanoidStateType.FallingDown and headHeight ~= nil do
						print("Falling")
						headHeight = root.Position.Y
						wait()
					end
				elseif state ~= Enum.HumanoidStateType.Freefall or state ~= Enum.HumanoidStateType.FallingDown and headHeight ~= nil then

					pcall(function()

						local fell = headHeight - root.Position.Y

						if fell >= lethalHeight then
							humanoid.Health = 0
						elseif fell >= damageHeight then
							humanoid.Health = humanoid.Health - math.floor(fell)
						end
					end)
				end
			end)
		end
	end)
end)

Honestly, I feel like I have no Idea what I am doing.

You there? β€β€β€Ž β€Žβ€β€β€Ž β€Žβ€β€β€Ž β€Žβ€β€β€Ž β€Žβ€β€β€Ž β€Žβ€β€β€Ž β€Žβ€β€β€Ž β€Žβ€β€β€Ž β€Žβ€β€β€Ž β€Žβ€β€β€Ž β€Žβ€β€β€Ž β€Žβ€β€β€Ž β€Žβ€β€β€Ž β€Žβ€β€β€Ž β€Žβ€β€β€Ž β€Žβ€β€β€Ž β€Ž

Ok try wrapping everything after you define the gliding variable into a while loop. Delete the repeat wait until.

Try while gliding.Value == false do

My reasoning behind this is because every other solution we have tried has only checked it once, or has checked it until the value becomes false, and then it stops checking it. I think we need to continually check it while it is false, so that when it becomes true, the code inside will stop.

The work has not been working since I added the gliding script to begin with. maybe give it an eye?

local player = game.Players.LocalPlayer

local RunService = game:GetService("RunService")
local ContextActionService = game:GetService("ContextActionService")

local char = script.Parent

falling = false

local gliding = game.Players.LocalPlayer:WaitForChild("Gliding")

char.Humanoid.StateChanged:Connect(function(_,state)
	if state == Enum.HumanoidStateType.Freefall then
		falling = true
		wait()
	elseif state ~= Enum.HumanoidStateType.Freefall or state == Enum.HumanoidStateType.Climbing then
		falling = false
		wait()
	end
end)

local function Glide(actionName, inputState)
	if inputState == Enum.UserInputState.Begin and falling then
		gliding.Value = true
		local lowgrav = Instance.new("BodyVelocity")
		lowgrav.Parent = char.Head
		lowgrav.MaxForce = Vector3.new(0, 100000, 0)
		lowgrav.P = 10000
		lowgrav.Velocity = Vector3.new(0, -10, 0)
		lowgrav.Name = "LowGravity"

	elseif falling == false or inputState == Enum.UserInputState.End or inputState == Enum.UserInputState.Cancel or inputState == Enum.UserInputState.None  then
		local lowgrab = char.Head:FindFirstChildOfClass("BodyVelocity")

		if lowgrab then
			char.Head.LowGravity:Destroy()
		end
		wait()
		gliding.Value = false

	end
end

game.ContextActionService:BindAction("Q", Glide, true, Enum.KeyCode.Q, Enum.KeyCode.ButtonA)

Climbing jumping death fall

What I understood after the translation is that you want the player to jump up and down, and if he makes mistakes and falls, he dies

If you are wrong with something, you can correct me

And if my post is outside the topic, sorry I just wanted to help

This is not what I am trying to achieve, the world progress will not be straightforward like an obby, I want to achieve a game where you can go anywhere, but still having a task to do, just like Mario 64.

It is just basic fall damage, just like any other game like Minecraft, Certain Mario games, Fortnite, Etc. No need to show a video to explain.

Take the fact that at least you tried!