So I am making a roblox ragdoll game in witch when you die, you turn into a ragdoll and the ragdoll stays in the game indefinitely(will change that at some point but its going to be a round based game). But when I reset my character, the ragdoll is very choppy but in server its smooth.
here is what Im talking about:
here is the code too if that helps and there are no errors:
local Players = game:GetService("Players")
local debris = game:GetService("Debris")
local remotvent = game.ReplicatedStorage.RagdollEvent
local plrevent = game.ReplicatedStorage.PlayerEvent
local function playerAdded(player)
player.CharacterAppearanceLoaded:Connect(function(character)
if game.ServerStorage.Ragdolls:FindFirstChild(character.Name) then
return
end
local humanoid = character:WaitForChild("Humanoid")
local baseragdoll = game.ServerStorage.Objects.Dummy:Clone()
-- save hats for later
local accessories = {}
for _, accessory in pairs(humanoid:GetAccessories()) do
table.insert(accessories, accessory:Clone())
end
for _,accessory in pairs(accessories) do
baseragdoll.Humanoid:AddAccessory(accessory)
end
-- remove hats
accessories = nil
for _,descendant in pairs(character:GetDescendants()) do
if descendant.Name == "Body Colors" and descendant:IsA("BodyColors") then
local bccopy = descendant:Clone()
bccopy.Parent = baseragdoll
end
if descendant:IsA("Shirt") or descendant:IsA("ShirtGraphic") then
local scopy = descendant:Clone()
scopy.Parent = baseragdoll
end
if descendant:IsA("Pants") then
local pcopy = descendant:Clone()
pcopy.Parent = baseragdoll
end
if descendant:IsA("CharacterMesh") then
local ccopy = descendant:Clone()
ccopy.Parent = baseragdoll
end
end
local meshhead = character:FindFirstChildWhichIsA("SpecialMesh")
if meshhead then
local meshhcopy = meshhead:Clone()
meshhcopy.Parent = baseragdoll.Head
end
local facedecal = character:FindFirstChildWhichIsA("Decal")
if character:findFirstChild("Head"):findFirstChild("face").Texture == nil then return end
baseragdoll:findFirstChild("Head"):findFirstChild("face").Texture = character.Head.face.Texture
baseragdoll.Name = character.Name .. "'s Ragdoll"
baseragdoll.Parent = game.ServerStorage.Ragdolls
end)
end
-- get existing players
for _, player in pairs(Players:GetPlayers()) do
playerAdded(player)
end
-- listen for new players
Players.PlayerAdded:Connect(playerAdded)
game:GetService('Players').PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
character:WaitForChild("Humanoid").Died:Connect(function()
local charragdoll = game.ServerStorage.Ragdolls[player.Name.."'s Ragdoll"]:Clone()
charragdoll.PrimaryPart.Velocity = Vector3.new(math.random(-2,2),0,math.random(-2,2))
charragdoll:SetPrimaryPartCFrame(CFrame.new(character.HumanoidRootPart.Position))
charragdoll.HumanoidRootPart.Orientation = character.HumanoidRootPart.Orientation
local Str = Instance.new("IntValue",charragdoll)
Str.Value = player.userId
charragdoll.Parent = workspace.Ragdolls
print("A remote event in happening for:",player)
remotvent:FireClient(player, charragdoll)
character:Destroy()
wait(5)
player:LoadCharacter()
local charcheck = workspace:WaitForChild(player.Name)
plrevent:FireClient(player, plrevent)
end)
end)
end)
