Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How would i detect if humanoid state has been interrupted?

I don't know how you would detect if state has been interrupted and after a second it would say if it got interrupted.

The script looks like this: local animation = script.Parent.Freefall

local humanoid = script.Parent.Parent.Parent.Humanoid

local character = humanoid.Parent

humanoid.FreeFalling:Connect(function()

wait(1)

if character:FindFirstChild("Rope") == nil then

humanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp, true)

humanoid:ChangeState(Enum.HumanoidStateType.Ragdoll)

local ActiveTracks = humanoid:GetPlayingAnimationTracks()

for _,v in pairs(ActiveTracks) do

v:Stop()

end

local load = humanoid:LoadAnimation(animation)

character.Animate.Disabled = true

load:Play()

humanoid.GettingUp:Connect(function()

load:Stop()

character.Animate.Disabled = false

end)

end

end)

1 answer

If by "interrupted" you mean changed, then you can use the Humanoid.StateChanged event.

Here's an example of the same:

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		char:FindFirstChild("Humanoid").StateChanged:Connect(function(old, new) -- old state and new state
			print("Humanoid went from "..tostring(old).." to "..tostring(new).."!")
			-- You can also check the old and new states to make things occur at certain points like falling down 
		end)
	end)
end)

Useful links and articles:


On a sidenote, please remember to use codeblocks when posting scripts as such:

Input

```lua print("Hello World!") ```

Output

print("Hello World!")

Please comment if you have any questions or I have made any mistakes

This discussion is preserved as it was. New answers, comments, and votes are closed.