I have a ragdoll script that change Motor6D and BallSocketConstraints enable property when a Ragdoll
attribute changes. In order to make players/NPC fall I change their state to Ragdoll
. For players, there a local script that listens to Ragdoll
attribute change and changes player’s state. However, for NPC it changes their state on server side. But for some reason it doesn’t seam to work and NPC just doesn’t change, even though it uses the same state change algorithm as player’s local script does which is what im struggling with.
Here how it looks on NPC and Player:
Here’s the code for Ragdoll script:
--Character is the NPC/Player's character itself
Character.AttributeChanged:Connect(function(Attribute)
if Attribute == "Ragdoll" then
local RagdollStatus = Character:GetAttribute(Attribute)
if RagdollStatus == true then
if not Player then --Check if it's an NPC
--Here the state change
Humanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp, false)
Humanoid:ChangeState(Enum.HumanoidStateType.Ragdoll)
end
--Joint is a table that contains Motor6D and BallSocket for the limb
for i, Joint in ipairs(Joints) do
Joint.Motor6D.Enabled = false
Joint.Socket.Enabled = true
end
else
if not Player then
Humanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp, true)
Humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
end
for _, Joint in ipairs(Joints) do
Joint.Motor6D.Enabled = true
Joint.Socket.Enabled = false
end
end
end
end)