(Alright, This time, I will post the code)
I am working on a system that allows the player to glide and avoid fall damage, but for some reason, the gliding script is making the fall damage script not break out of the loop
Here is the fall damage script
-- Objects
local settingsDir = script.Settings
function getSetting (name)
return settingsDir and settingsDir:FindFirstChild(name) and settingsDir[name].Value
end
-- Variables
local damageHeight = getSetting("Damaging height") or 14 -- The height at which the player will start getting damaged at
local lethalHeight = getSetting("Lethal height") or 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 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 this is what I have of the gliding script
local player = game.Players.LocalPlayer
local RunService = game:GetService("RunService")
local ContextActionService = game:GetService("ContextActionService")
local char = script.Parent
falling = false
char.Humanoid.StateChanged:Connect(function(_,state)
if state == Enum.HumanoidStateType.Freefall then
falling = true
wait()
elseif state ~= Enum.HumanoidStateType.Freefall then
falling = false
wait()
end
end)
local function Glide(actionName, inputState)
if inputState == Enum.UserInputState.Begin and falling then
script.Parent.Falldamage.TakeDamage.Value = false
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:Remove()
end
wait(.1)
script.Parent.Falldamage.TakeDamage.Value = true
end
end
game.ContextActionService:BindAction("Q", Glide, true, Enum.KeyCode.Q, Enum.KeyCode.ButtonA)
Both of these scripts go under “StarterCharacterScripts” inside “StarterPlayer” and each is called “FallDamage” and “Gliding” respectfully, And the fall damage script must have a BoolValue instance that is active and called “TakeDamage”
I have been trying absolutely everything to try and fix this, but the things keep breaking.
Any help?