I’ve been working on this portion of my script for a couple hours, and I can’t find anything that might help with detecting when the magnitude changes to X (let’s say a magnitude of 90) when the player enters into freefall.
I’ve looked for similar solutions, but none of what I’ve found on the devforum were relevant to magnitude. For the time being, I’m taking certain aspects of other scripts shared among the devforum and editing them to make this example.
I’ve tried a variety of methods, but I can’t find any type of solution for it. I know it’s possible, but I just don’t understand how I can make this happen as of now.
Any and all help is appreciate, here’s my code:
local character = script.Parent
local username = character.Name
local humanoid = character.Humanoid
local rootPart = humanoid.RootPart or character.HumanoidRootPart
local magnitude = math.abs(math.round(rootPart.Velocity.Magnitude))
local damageMagThreshold = 90
local falling
local ragdolled, canGetUp = false, true
--Only starts when I leave the suggested state
humanoid.StateChanged:Connect(function(oldState, newState)
--[[Detects when the player is freefalling, as opposed to
starting when it has reached >= damageMagThreshold]]
if newState == Enum.HumanoidStateType.Freefall and not ragdolled then
print("freefalling!")
ragdolled = true
canGetUp = false
task.delay(1, function()
canGetUp = true
end)
humanoid.AutoRotate = false
humanoid.PlatformStand = true
--ragdoll function
end
end)
In your case, you would want to get the root part’s AssemblyLinearVelocity property changed signal, which will fire whenever the player is moving. You can then use the magnitude at that given time to check when the player is freefalling.
You can use the Players.CharacterAdded event to detect when a player’s Magnitude has changed. The event is triggered whenever a player’s Magnitude changes. You can then use the Player.Character property to access the Character and its Humanoid object, which contains a MaxForce property that stores the current Magnitude value.
I’ve been having trouble understanding what you mean, I’ve also been playing with it to see how it works, but the behavior I’ve been observing is that, when I change the velocity itself with a block of code, that’s the only time where it prints. I feel there’s something I’m missing here that I’m ignorant to; how would I go about applying this to achieve my goal?
If i’m not mistaken if you want to detect a change in a player’s magnitude AKA movement you should be
detecting it using Humanoid.MoveDirection
This code right here detects the Character’s change in movement only if they’re free falling
and then stop detecting the change if the Humanoid is not freefalling, to avoid a memory leak.
local Connections = {}
humanoid.StateChanged:Connect(function(oldState, newState)
if newState == Enum.HumanoidStateType.Freefall then
Connections["MagnitudeChange"] = humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
print("Player is moving while freefalling")
end)
else
-- If the player is not free falling then stop detecting the change in movement
if Connections["MagnitudeChange"] then
print("Disconnect")
Connections["MagnitudeChange"]:Disconnect()
end
end
end)
No, I already covered that. I went into deeper detail in the original post, but I’m looking for when the rootPart hits a total magnitude of 90 or more while freefalling.
Magnitude; a unit that stands for the summation of the total velocity value as a single number value. Magnitude can be an integer, or a float based on the calculations you make (integer in this case for simplicity).
To apply this to the script, I’m trying to configure it to where the script detects when the magnitude/total velocity is greater than or equal to a set example; such is 90.
I’ve tried that, but whenever I try to detect it that way, it always renders either after the state changes or doesn’t render at all; never mid-air at 90.
The closest I could get was 50, which is not suitable at all for the game I’m trying to make.
I’ve tested the terminal velocity can be as much as little under 300 from what I’ve gathered. There’s no terminal velocity being reached until then. 90 is within the range 0 - ~300, which is what I’m stuck on.
game["Run Service"].Stepped:Connect(function()
local Player = game.Players:FindFirstChildOfClass("Player")
if Player then
if Player.Character then
local HRP = Player.Character:FindFirstChild("HumanoidRootPart")
if HRP then
print((Vector3.new(0, HRP.AssemblyLinearVelocity.Y, 0)).Magnitude)
end
end
end
end)
Turns out, this actually helped. I looked more into this, and cooked up a result I’m very happy with.
Whoever finds any flaws with this script, or it becomes outdated, please contact me directly, or post on this board so I can update it as the most efficient result (Consider it a challenge )
local interval = .1
local elapsed = 0
function ragdoll()
--Your ragdoll system here
end
humanoid.StateChanged:Connect(function(oldState, newState)
if newState == Enum.HumanoidStateType.Freefall then
print("Falling; starting check")
game["Run Service"].Heartbeat:Connect(function(deltaTime)
elapsed += deltaTime
if elapsed >= interval then
elapsed -= interval
magnitude = math.abs(math.round(rootPart.Velocity.Magnitude))
if magnitude >= 90 and not ragdolled then
ragdoll()
end
end
end)
end
end)
^^ Whoever wants to experiment with the script, go right ahead