So I have this script that works fine when you take damage, but once you regain it, the ragdoll does not stop, any help?
local plr = game.Players.LocalPlayer
local char = plr.Character
local hum = plr.Character.Humanoid
dog = false
while true do
if hum.Health <= 15 and dog == false then
dog = true
hum.WalkSpeed = 0
hum.JumpPower = 0
local setEnabled = hum:GetState() ~= Enum.HumanoidStateType.Physics
hum:ChangeState(setEnabled and Enum.HumanoidStateType.Physics or Enum.HumanoidStateType.GettingUp)
char.Animate.Disabled = setEnabled
wait()
end
if hum.Health >= 39 and dog == true then
dog = false
hum.WalkSpeed = 8
hum.JumpPower = 40
for _,v in pairs(hum:GetPlayingAnimationTracks()) do
v:Stop(0)
end
end
wait()
end
Instead of using a while loop to constantly check your humanoid’s health,
use an event called HealthChanged which fires whenever the humanoids health changes.
You can use this in a way such as:
hum.HealthChanged:Connect(function()
–your logic for ragdoll
end)
As for your ragdoll issue, I’m not sure what the issue is but I can guarantee there’s no need to set Animate to disabled.
I think your issue there now is that you do not reenable Animate. You see you only change it’s Disabled property while the player’s health is less than 15 and you only change their state when their health is less than 15.
You’d want to change their state in the below if statement ‘if hum.Health >= 39’ and reenable the Animate script.
if hum.Health >= 39 and dog == true and setEnabled then
dog = false
hum.WalkSpeed = 8
setEnabled = false
hum.JumpPower = 40
for _,v in pairs(hum:GetPlayingAnimationTracks()) do
v:Stop(0)
end
end
wait()
end
end)
No, SetEnabled is local to the top if statement scope. remove the ‘and setEnabled’ and inside the if statement you’ve just provided, set the humanoid’s state back to ‘GettingUp’ and reenable their Animate script.
if hum.Health >= 39 and dog == true and setEnabled then
dog = false
hum.WalkSpeed = 8
hum.JumpPower = 40
hum:ChangeState(Enum.HumanoidStateType.GettingUp)
char.Animate.Disabled = false
for _,v in pairs(hum:GetPlayingAnimationTracks()) do
v:Stop(0)
end
end
wait()
end
end)
I rmeoved the SetEnabled and its still not working, heres what I have
if hum.Health >= 39 and dog == true then
dog = false
hum.WalkSpeed = 8
hum.JumpPower = 40
hum:ChangeState(Enum.HumanoidStateType.GettingUp)
char.Animate.Disabled = false
for _,v in pairs(hum:GetPlayingAnimationTracks()) do
v:Stop(0)
end
end
wait()
end
end)
It might help by showing the script im going off of
local character = script.Parent
local humanoid = character.Humanoid
game:GetService("ContextActionService"):BindAction("Ragdoll me", function(_,input)
if input == Enum.UserInputState.Begin then
local setEnabled = humanoid:GetState() ~= Enum.HumanoidStateType.Physics
humanoid:ChangeState(setEnabled and Enum.HumanoidStateType.Physics or Enum.HumanoidStateType.GettingUp)
character.Animate.Disabled = setEnabled
if setEnabled then
for _,v in pairs(humanoid:GetPlayingAnimationTracks()) do
v:Stop(0)
end
end
end
end, false, Enum.KeyCode.R)
if hum.Health >= 39 and dog == true then
dog = false
hum.WalkSpeed = 8
hum.JumpPower = 40
hum:ChangeState(Enum.HumanoidStateType.GettingUp)
char.Animate.Disabled = false
for _,v in pairs(hum:GetPlayingAnimationTracks()) do
v:Stop(0)
end
end
wait()
end
end)