I want to print the falling speed of the player as they fall, but instead it only prints when the player has landed. How can I get this to constantly print while they fall (so I can kill them if they reach certain speeds)
Humanoid.StateChanged:Connect(function(old, new)
if old ~= Enum.HumanoidStateType.Freefall then return end
print(Character.HumanoidRootPart.AssemblyLinearVelocity.Y)
end)
Basically, you can have a variable called “recording” and by default it is set to false.
local recording = false
Then, when the player jumps off something, it sets recording to true. But when the player lands, it sets it to false.
local recording = false
script.Parent.HumanoidChanged:Connect(function(old, new)
if new == Enum.HumanoidStateType.Freefall then
recording = true
else if new == Enum.HumanoidStateType.Landed or new == Enum.HumanoidStateType.Running then
recording = false
end
end)
Now, in a while wait() loop (there is probably a less laggier alternative to this, but I’m not sure) if it is recording, then it prints the players falling speed.
Full script:
local recording = false
script.Parent.Humanoid.StateChanged:Connect(function(old, new)
if new == Enum.HumanoidStateType.Freefall then
recording = true
else if new == Enum.HumanoidStateType.Landed or new == Enum.HumanoidStateType.Running then
recording = false
end
endend)
while wait() do
if recording == true then
print(script.Parent.HumanoidRootPart.AssemblyLinearVelocity.Y)
end
end
local lastY = 0
Humanoid.StateChanged:Connect(function(old, new)
if new == Enum.HumanoidStateType.Freefall then
while Humanoid:GetState() == Enum.HumanoidStateType.Freefall do
lastY = Character.HumanoidRootPart.AssemblyLinearVelocity.Y
wait(0.1)
end
end
if old.Name == "Freefall" then -- sry kinda lazy to type in boring long enum.blablabla
-- Player landed with Y velocity lastY
lastY = 0
end
end)