You can write your topic however you want, but you need to answer these questions:
- What do you want to achieve? Keep it simple and clear!
I’m working on a system that allows the player to pick up and throw NPCS that are rendered unconscious by my system. I create the NPC’s with a table and have a Body property that holds the NPC’S physical body. This is what that looks like.
function NPC_HANDLER:newNPC(SpawnPoint:CFrame,Variant,Parent)
local Model = game.ReplicatedStorage.NPCS.Patient
local NPC_ID = tostring(math.random(1,999999999))
NPC_Table[NPC_ID]= {
Blood = {},
Body = Model:Clone(),
SpawnLocation = SpawnPoint,
Parent = Parent,
KnockOut = function()
NPC_Table[NPC_ID].Body:SetAttribute("Unconscious",true)
print("Knocked Out")
end,
WakeUp = function()
NPC_Table[NPC_ID].Body:SetAttribute("Unconscious",false)
end,
RemoveFactor = function(FactorName)
NPC_Table[NPC_ID].Blood[FactorName] = nil
end,
}
spawnNPC(NPC_ID)
return NPC_Table[NPC_ID]
end
if closestChar:GetAttribute("Unconscious") then
closestChar.IsRagdoll.Value = false
end
for _, v in closestChar:GetDescendants() do
if v:IsA("BasePart") then
v.CollisionGroup = "Carry"
end
end
AnimationHandler:PlayAnimation(closestChar, animFolder.Carried)
AnimationHandler:PlayAnimation(Character, animFolder.Carrying)
closestChar.HumanoidRootPart.CFrame = HRP.CFrame * CFrame.new(0, 3, 0)
Character:SetAttribute("Carrying", closestChar:GetAttribute("ID"))
closestChar:SetAttribute("CarriedBy", Player.UserId)
local weld = Instance.new("WeldConstraint")
weld.Parent = HRP
weld.Part0 = HRP
weld.Part1 = closestChar.HumanoidRootPart
weld.Name = "CarryWeld"
(Keep in mind that ragdoll doesnt do anything right now)
- What is the issue? Include screenshots / videos if possible!
The problem is that for some reason, when welding the NPC to the character, it becomes buggy. Instead of rotating normally, when holding the NPC, the characters rotation is delayed. (the NPC on the left was loaded 2 seconds after the first)
The strange part is that the only fix is to spawn the NPC right after the game starts. I trimmed it down to this line of code.
Body = Model:Clone()
It seems that something happens to the model in replicated storage but Im not sure what that could be. I isolated this script so nothing is touching the NPC’S (so its not a race condition thing).
- What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I looked on reddit, devForum, youtube, and I couldnt find anything. I changed the model that it references. I tried every type of weld. I changed a bunch of different Humanoid states like physics, seated, platform stand. Nothing changes the result.