Model:SetPrimaryPartCFrame() not working properly

Hello,

I’m having issues with moving a ragdoll by using SetPrimaryPartCFrame().

Every time i run the script, this error shows up:

ServerScriptService.RagdollSpawner:2: attempt to index nil with 'SetPrimaryPartCFrame'

(Im using remote events to make the ragdolls spawn at the given position)

The lines of code that fire the server:

local RagdollCharacter = game.ReplicatedStorage.RagdollPlayerCharacter

local Position = game.Workspace.PlayerCharacter1:GetPrimaryPartCFrame()

local RagdollClone = RagdollCharacter:Clone()
RagdollClone.Parent = game.Workspace

game.ReplicatedStorage.SpawnRagdoll:FireServer(RagdollClone, Position)

The remote event script:

game.ReplicatedStorage.SpawnRagdoll.OnServerEvent:Connect(function(Player, Ragdoll, Position)

Ragdoll:SetPrimaryPartCFrame(Position)

end)

I cant find any errors in both of my scripts, there are also no topics that have proper answers to this error.

Any help is appreciated.

The problem is that you created something in a client script and it isn’t replicating, so it shows up as nil.
You are going to need to create Ragdoll inside of OnServerEvent instead.

1 Like

Nevermind, i just set the primary part’s CFrame in the local script itself, it works.

Ok. Just keep in mind the ragdoll won’t show up for other players, then. I’m not sure if you desire that or not.

My game is single player - it wont matter.

1 Like

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