You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Roblox Ragdoll系统异常:解除布偶状态后再次触发布偶

Roblox布偶系统解除状态时重复触发Bug问题

我开发了一套Roblox Ragdoll布偶系统,遇到异常Bug:尝试解除布偶状态时,角色会再次进入布偶状态。该Bug仅在2名及以上玩家同时游戏时出现,输出窗口无任何错误提示。我怀疑问题出在事件(Events)逻辑上,尝试将系统改为客户端侧实现也未能解决问题。

服务器脚本代码

local Event = game.ReplicatedStorage:FindFirstChild('Ragdoll')
local IsRag = false
local IsStudio = false
local plr = nil
local cooldown = 3
local CanRagDoll = true

if game:GetService('RunService'):IsStudio() then
    IsStudio = true
    print('User in studio')
else
    IsStudio = false
    print('User not in studio')
end

local UserInputService = game:GetService('UserInputService')
function Ragdoll(Player, Character)
    for i,joint in pairs(Character:GetDescendants()) do
        if joint ~= nil and joint:IsA('Motor6D') then
            print('Found Joint.')
            Character:FindFirstChildOfClass('Humanoid').PlatformStand = true
            task.wait(0.01)
            for i,v in pairs(workspace:GetDescendants()) do
                if v:IsA('Folder') and v ~= nil then
                    if v.Name == 'HitBoxes'..Player.name then
                        for i,j in pairs(v:GetChildren()) do
                            if j:IsA('Part') and j ~= nil then
                                j.CanCollide = true
                            end
                        end
                    end
                end
            end
            local socket = Instance.new('BallSocketConstraint')
            local a1 = Instance.new('Attachment')
            local a2 = Instance.new('Attachment')
            a1.Position = joint.C0.Position
            a2.Position = joint.C1.Position
            a1.Name = 'RagdollAttachment'
            a2.Name = 'RagdollAttachment'
            socket.Parent = joint.Parent
            socket.Attachment0 = a1
            socket.Attachment1 = a2
            socket.LimitsEnabled = true
            socket.TwistLimitsEnabled = true
            a1.Parent = joint.Part0
            a2.Parent = joint.Part1
            joint.Enabled = false
        end
    end
end
function UnRagDoll(Player, Character)
    Character:FindFirstChildOfClass('Humanoid').PlatformStand = false

    for i,joint in pairs(Character:GetDescendants()) do
        if joint ~= nil and joint:IsA('Motor6D') then
            joint.Enabled = true
            for i,v in pairs(workspace:GetDescendants()) do
                if v:IsA('Folder') and v ~= nil then
                    if v.Name == 'HitBoxes'..Player.name then
                        for i,j in pairs(v:GetChildren()) do
                            if j:IsA('Part') and j ~= nil then
                                j.CanCollide = false
                            end
                        end
                    end
                end
            end
            Character:FindFirstChild('HumanoidRootPart').Orientation = Vector3.new(0,Character:FindFirstChild('Torso').Orientation.Y,0)
            Character:FindFirstChild('HumanoidRootPart').Position = Character:FindFirstChild('Torso').Position
            print('Removed!')
        end
    end
end

Event.OnServerEvent:Connect(function(player)
    plr = player
    if player.Name == plr.Name and CanRagDoll == true then
        CanRagDoll = false
        if IsRag == false then
            IsRag = true
            Ragdoll(player, player.Character)
        else
            IsRag = false
            UnRagDoll(player, player.Character)
            for i,v in pairs(player.Character:GetDescendants()) do
                if v:IsA('BallSocketConstraint') and v ~= nil then
                    v:Destroy()
                end
            end
        end
        
        task.wait(cooldown)
        CanRagDoll = true
    else
        warn('Wrong player!')
    end
end)

while task.wait() do
    if IsRag == true and plr.Character:FindFirstChildOfClass('Humanoid').FloorMaterial == Enum.Material.Air then
        game.ReplicatedStorage.FixJumpBug:InvokeClient(plr)
    end
end
print('Made by OldMadEgg! Follow me at: https://www.roblox.com/users/3873716276/profile ')
-- Credits to OldMadEgg!

客户端脚本代码

local UIS = game:GetService('UserInputService')
local event = game.ReplicatedStorage.Ragdoll
local plr = game.Players.LocalPlayer

UIS.InputBegan:Connect(function(input, processed)
    if processed then return end
    
    if input.KeyCode == Enum.KeyCode.R or input.KeyCode == Enum.KeyCode.ButtonY and game.Players.LocalPlayer.Character:FindFirstChildOfClass('Humanoid').Health ~= 0 then
        event:FireServer(plr)
    end
end)

game.ReplicatedStorage.FixJumpBug.OnClientInvoke = function()
    game.Players.LocalPlayer.Character:FindFirstChildOfClass('Humanoid').PlatformStand = true
end

工作区截图

工作区截图

内容的提问来源于stack exchange,提问作者OldMadEgg

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 01:42:03