Top.Mail.Ru
Ответы

Помогите сделайте скрипт в роблокс студио!

Привет! Помогите, пожалуйста, сделать скрипт для падения (fall ragdoll): когда игрок падает в яму, чтобы срабатывал ragdoll, и он вращался, как в симуляторе в низу канава. Срочно нужна помощь! Сделать для R6!

По дате
По Рейтингу
Аватар пользователя
Мудрец
7мес

На

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
 local Players = game:GetService("Players") 
local RunService = game:GetService("RunService") 
local PhysicsService = game:GetService("PhysicsService") 
 
local SETTINGS = { 
    FALL_THRESHOLD = 50, 
    ROTATION_SPEED = Vector3.new(5, 5, 5), 
    RAGDOLL_DURATION = 5, 
    COLLISION_GROUP = "Ragdoll" 
} 
 
PhysicsService:CreateCollisionGroup(SETTINGS.COLLISION_GROUP) 
PhysicsService:CollisionGroupSetCollidable(SETTINGS.COLLISION_GROUP, "Default", true) 
 
local function setRagdollState(character, enable) 
    local humanoid = character:FindFirstChildOfClass("Humanoid") 
    if humanoid then 
        humanoid:ChangeState(enable and Enum.HumanoidStateType.Physics or Enum.HumanoidStateType.GettingUp) 
    end 
 
    for _, part in ipairs(character:GetDescendants()) do 
        if part:IsA("BasePart") then 
            part.CanCollide = enable 
            PhysicsService:SetPartCollisionGroup(part, enable and SETTINGS.COLLISION_GROUP or "Default") 
        elseif part:IsA("Motor6D") and part.Name ~= "Neck" then 
            if enable then 
                local a0, a1 = Instance.new("Attachment"), Instance.new("Attachment") 
                a0.Parent, a1.Parent = part.Part0, part.Part1 
                a0.CFrame, a1.CFrame = part.C0, part.C1 
 
                local ballSocket = Instance.new("BallSocketConstraint") 
                ballSocket.Attachment0, ballSocket.Attachment1 = a0, a1 
                ballSocket.LimitsEnabled = true 
                ballSocket.TwistLimitsEnabled = true 
                ballSocket.Parent = part.Parent 
 
                part.Enabled = false 
            else 
                part.Enabled = true 
            end 
        elseif part:IsA("BallSocketConstraint") then 
            part:Destroy() 
        end 
    end 
end 
 
local function onCharacterAdded(character) 
    local rootPart = character:WaitForChild("HumanoidRootPart") 
    local lastY = rootPart.Position.Y 
    local isFalling = false 
 
    RunService.Heartbeat:Connect(function() 
        if not rootPart.Parent then return end 
 
        local currentY = rootPart.Position.Y 
        if lastY - currentY > SETTINGS.FALL_THRESHOLD and not isFalling then 
            isFalling = true 
            setRagdollState(character, true) 
            rootPart.AssemblyAngularVelocity = SETTINGS.ROTATION_SPEED 
 
            task.delay(SETTINGS.RAGDOLL_DURATION, function() 
                if character.Parent then 
                    setRagdollState(character, false) 
                    isFalling = false 
                end 
            end) 
        end 
        lastY = currentY 
    end) 
end 
 
Players.PlayerAdded:Connect(function(player) 
    player.CharacterAdded:Connect(onCharacterAdded) 
end) 
 
for _, player in Players:GetPlayers() do 
    if player.Character then onCharacterAdded(player.Character) end 
end