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!
Hello! I’m trying to create a body-carrying system with ragdolls using SpringConstraint. - What is the issue? Include screenshots / videos if possible!
The player who is carrying a body starts floating around. I don’t have any idea what the issue is.
-
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I don’t have any idea where the issue is, so i haven’t found anything.
-- CarryServer
-- Server Script(ServerScriptService)
local carryEvent = game:GetService("ReplicatedStorage"):WaitForChild("CarryEvent")
local ragdollRemote = game.ReplicatedStorage:WaitForChild("RagdollRemote")
local function Welding(player, weldPart, attachPos)
local weld = Instance.new("SpringConstraint", player.Character["Right Arm"])
weld.LimitsEnabled = true
weld.MaxLength = 1
weld.Attachment1 = player.Character["Right Arm"].RightGripAttachment
if (weldPart:FindFirstChild("CarryingAttach") ~= nil) then
weldPart:FindFirstChild("CarryingAttach"):Destroy()
end
local attach = Instance.new("Attachment", weldPart)
attach.Name = "CarryingAttach"
attach.Position = attachPos:ToObjectSpace(weldPart.CFrame).p
weld.Attachment0 = attach
if weldPart.Parent ~= nil and weldPart.Parent:FindFirstChildOfClass("Humanoid") ~= nil then
weldPart.Parent.PrimaryPart:SetNetworkOwner(player)
ragdollRemote:FireClient(player, weldPart.Parent, true)
return weld
end
end
local function UnWelding(character, weldPart)
character["Right Arm"]:FindFirstChildOfClass("SpringConstraint"):Destroy()
end
carryEvent.OnServerEvent:Connect(function(player, position, instance, isHolding)
local character = player.Character
if not isHolding then
local weld = Welding(player, instance, CFrame.new(position))
else
UnWelding(character, instance)
end
end)
-- Carry
-- Local Script(StarterPlayerScripts)
local userInput = game:GetService("UserInputService")
local carryKey = Enum.KeyCode.E
local carryEvent = game:GetService("ReplicatedStorage"):WaitForChild("CarryEvent")
local player = game.Players.LocalPlayer
local playerCharacter = player.Character or player.CharacterAdded:Wait()
local mouse = player:GetMouse()
local camera = workspace.CurrentCamera
local isHolding = false
local track
userInput.InputBegan:Connect(function(key, process)
if process then
return
end
if (key.KeyCode == carryKey) then
local rayCamera = camera:ScreenPointToRay(mouse.x, mouse.Y)
local raycastResult = workspace:Raycast(rayCamera.Origin, rayCamera.Direction * 25, RaycastParams.new())
if (isHolding) then
track:Stop()
playerCharacter.Humanoid.WalkSpeed = 14
carryEvent:FireServer(raycastResult.Position, raycastResult.Instance, isHolding)
isHolding = not isHolding
else
if math.abs((raycastResult.Position - playerCharacter.Head.Position).Magnitude) < 7 then
track = playerCharacter.Humanoid:LoadAnimation(script.CarryAnimation)
playerCharacter.Humanoid.WalkSpeed = 5
track:Play()
carryEvent:FireServer(raycastResult.Position, raycastResult.Instance, isHolding)
isHolding = not isHolding
end
end
end
end)
--RagdollHandler
-- Local script(StarterCharacterScripts.Ragdoll)
local player = game.Players.LocalPlayer
local ragdollRemote = game.ReplicatedStorage:WaitForChild("RagdollRemote")
local shiftLock = player.PlayerScripts:WaitForChild("CustomShiftLock").SmoothShiftLock.ToggleShiftLock
ragdollRemote.OnClientEvent:Connect(function(char, enable)
if enable then
char.Humanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp, false)
char.Humanoid:ChangeState(Enum.HumanoidStateType.Ragdoll)
else
shiftLock:Fire(true)
char.Humanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp, true)
char.Humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
end
if char == player.Character then
shiftLock:Fire(not enable)
end
end)
-- Ragdoll
-- StarterCharacterScripts
local humanoid = script.Parent:WaitForChild("Humanoid")
local ragdollRemote = game.ReplicatedStorage:WaitForChild("RagdollRemote")
local ragdolled = ("Ragdoll")
humanoid.BreakJointsOnDeath = false
local function CreateSockets()
for index,joint in pairs(script.Parent:GetDescendants()) do
if joint:IsA("Motor6D") then
local socket = Instance.new("BallSocketConstraint")
local a1 = Instance.new("Attachment")
local a2 = Instance.new("Attachment")
a1.Parent = joint.Part0
a2.Parent = joint.Part1
socket.Parent = joint.Parent
socket.Attachment0 = a1
socket.Attachment1 = a2
a1.CFrame = joint.C0
a2.CFrame = joint.C1
socket.LimitsEnabled = true
socket.TwistLimitsEnabled = true
end
end
end
CreateSockets()
local function ToggleRagdoll(ragdoll)
local player = game.Players:GetPlayerFromCharacter(script.Parent)
ragdollRemote:FireClient(player, script.Parent, ragdoll)
local enabledState = not ragdoll
for index, joint in pairs(script.Parent:GetDescendants()) do
if joint:IsA("Motor6D") then
joint.Enabled = enabledState
end
end
script.Parent:SetAttribute(ragdolled, ragdoll)
end
script.Parent.Ragdolize.Event:Connect(function()
if script.Parent:GetAttribute(ragdolled) == false then
ToggleRagdoll(true)
else if script.Parent:GetAttribute("Difficulty") == 0 then
ToggleRagdoll(false)
end
end
end)
humanoid.Died:Connect(function()
ToggleRagdoll(true)
end)
I would greatly appreciate it if you could find a fix to this problem!