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)
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.
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.
-- 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.
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)
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.