I have a ragdoll script so when you press "E" you go into ragdoll
Problem is, if standing still and you press "E" the player goes into ragdol but is frozen in the air.
The ragdoll only works when moving and pressing "E" at the same time.
Could someone please help me make it so the player gets flung a tiny bit so the ragdoll is smoother?
My explorer: https://gyazo.com/7bf0424dca8b7945283ebccee697f597
My script:
local remote = script:WaitForChild("RemoteEvent")
local client = script:WaitForChild("LocalScript")
local sockets = {}
remote.Parent = game.ReplicatedStorage
local ragdoll = function(plr,chr)
local humanoid = chr:WaitForChild("Humanoid")
chr.HumanoidRootPart.CFrame = chr.HumanoidRootPart.CFrame * CFrame.new(math.random(),math.random(),math.random())
for i,v in next,chr:GetDescendants() do
if v:IsA("Motor6D") and v.Parent.Name ~= "Head" then
local attachment0,attachment1 = Instance.new("Attachment",v.Part0),Instance.new("Attachment",v.Part1)
attachment0.CFrame = v.C0
attachment1.CFrame = v.C1
attachment0.Name = "bone"
attachment1.Name = "bone"
local socket = Instance.new("BallSocketConstraint",v.Part0)
socket.Attachment0 = attachment0
socket.Attachment1 = attachment1
socket.Name = "bone"
sockets[plr][v] = v.Parent
v.Parent = nil
end
end
chr.HumanoidRootPart.CanCollide = false
end
local function jump(plr,chr)
for i,v in pairs(sockets[plr]) do
i.Parent = v
end
for i,v in next,chr:GetDescendants() do
if v.Name == "bone" then
v:Destroy()
end
end
end
game.Players.PlayerAdded:Connect(function(p)
p.CharacterAdded:Connect(function(c)
sockets[p] = {}
local newclient = client:Clone()
newclient.Parent = c
newclient.Disabled = false
end)
end)
remote.OnServerEvent:Connect(function(player,state)
local character = player.Character if not character then return end
local humanoid = character.Humanoid if not humanoid then return end
if state == "Ragdoll" then
ragdoll(player,character)
end
if state == "Jump" then
jump(player,character)
end
end)
The local script inside:
--made by imperialy aka metaindex
local remote = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")
local userinputservice = game:GetService("UserInputService")
local db = true
local connection;
local controls = require(game:GetService("Players").LocalPlayer.PlayerScripts.PlayerModule):GetControls()
local function ragdoll()
connection = game:GetService("RunService").Stepped:Connect(function()
for i,v in pairs(game.Players.LocalPlayer.Character:GetChildren()) do
if v:IsA("Humanoid") then
v:ChangeState(Enum.HumanoidStateType.Ragdoll)
end
if v.Name == "Torso" or v.Name == "UpperTorso" then
workspace.CurrentCamera.CameraSubject = v
end
end
end)
controls:Disable()
end
local function jump()
connection:Disconnect()
controls:Enable()
workspace.CurrentCamera.CameraSubject = game.Players.LocalPlayer.Character.Humanoid
end
userinputservice.InputBegan:Connect(function(Input,Typing)
if Typing then return end
if Input.KeyCode == Enum.KeyCode.E then
db = not db
if not db then
print('fired')
remote:FireServer("Ragdoll")
ragdoll()
else
remote:FireServer("Jump")
jump()
end
end
end)
Help!!
