Falling script not working

Client Sided Script not running. It’s meant to run after that certain amount of studs


-- Services
local RS = game:GetService("ReplicatedStorage")

-- Folders
local RSStorage = RS.Storage
local RSEvents = RSStorage.RemoteEvents

-- Character/Humaniod
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local char = Player.Character
local hum = char:WaitForChild("Humanoid")
local HRP = hum:WaitForChild("HumanoidRootPart")

-- Values
local Height
local RollHeight = 20
local FallDamageHeight = 35


hum.StateChanged:Connect(function(OldState, NewState)
	if NewState == Enum.HumanoidStateType.Landed then
		local Height = -HRP.Velocity.Y
		if Height >= 10 and Height <= 100 then
			RSEvents.MovementEvents.Roll:FireServer(char)
		end
	end
end)

local LandAnim = script:FindFirstChild("Land")
local playAnim = hum:LoadAnimation(LandAnim)

hum.StateChanged:Connect(function(OldState,NewState)
	if NewState == Enum.HumanoidStateType.Landed then
		local Height = -HRP.Velocity.Y
		print ("Landed")
		if Height >= RollHeight and Height <= 10 then
			playAnim:Play()
			wait(1)
			playAnim:Stop()
		end
	end
end) 


hum.StateChanged:Connect(function(OldState,NewState)
	if NewState == Enum.HumanoidStateType.Landed then
		local Height = -HRP.Velocity.Y
		print ("Lande")
		if Height >= FallDamageHeight then 
			RSEvents.MovementEvents.FallDamage:FireServer(char)
		end
	end
end)

Slight modifications.

-- Services
local RS = game:GetService("ReplicatedStorage")

-- Folders
local RSStorage = RS.Storage
local RSEvents = RSStorage.RemoteEvents

-- Character/Humanoid
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local char = Player.Character or Player.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local HRP = char:WaitForChild("HumanoidRootPart")

-- Values
local RollHeight = 20
local FallDamageHeight = 35

hum.StateChanged:Connect(function(_, NewState)
	if NewState == Enum.HumanoidStateType.Landed then
		local Height = -HRP.Velocity.Y
		if Height >= RollHeight and Height < FallDamageHeight then
			RSEvents.MovementEvents.Roll:FireServer(char)
			local LandAnim = script:FindFirstChild("Land")
			if LandAnim then
				local playAnim = hum:LoadAnimation(LandAnim)
				playAnim:Play()
				task.wait(1)
				playAnim:Stop()
			end
		elseif Height >= FallDamageHeight then 
			RSEvents.MovementEvents.FallDamage:FireServer(char)
		end
	end
end)

Player.CharacterAdded:Wait() as a fail safe for timing.
Combined all StateChanged connections into a single connection.
Animation should only play when a valid Land animation is found.


-- Services
local RS = game:GetService("ReplicatedStorage")

-- Folders
local RSStorage = RS.Storage
local RSEvents = RSStorage.RemoteEvents

-- Character/Humanoid
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local char = Player.Character or Player.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local HRP = char:WaitForChild("HumanoidRootPart")

-- Values
local RollHeight = 20
local FallDamageHeight = 35

-- Load Animation
local LandAnim = script:FindFirstChild("Land")
local playAnim = LandAnim and hum:LoadAnimation(LandAnim)

-- Handle StateChanged
hum.StateChanged:Connect(function(_, NewState)
    if NewState == Enum.HumanoidStateType.Landed then
        local Height = -HRP.Velocity.Y
        print("Landed with Height: " .. Height)
        
        if Height >= RollHeight and Height <= 10 then
            if playAnim then
                playAnim:Play()
                wait(1)
                playAnim:Stop()
            end
        end
        
        if Height >= FallDamageHeight then
            RSEvents.MovementEvents.FallDamage:FireServer(char)
        end
    end
end)

I love it, same attack plan! :rofl: These always seem to come down to this line.
local char = Player.Character or Player.CharacterAdded:Wait()

or Player.CharacterAdded:Wait() VIP call!

1 Like

I always mess up on the easiest lines I swear

1 Like

Ya, believing that is locked in causes logic errors after. A lesson you only only need to learn once.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.