Lua Roblox 角色死亡重生

如何使这段代码工作?当我点击墙壁时,Judoon 角色必须再生(重生),但只有在他死亡时才能这样做。[![Regenerate][1]][1] 当我点击墙壁时,我的 Judoon 角色必须重生,但只有当他死亡时才能这样做。

此外,我怎样才能引入 Regen 按钮,使脚本与 Judoon 模型分离,但它应该能工作。如果你把 Regen 脚本放到 Workspace 中,与 Judoon 文件夹分离,它将无法工作。

   local box = script.Parent

local debounce = false

-- 不要将这个和你的模型一起组合!

local everything = {Judoon}
local names = {Judoon}

local children = game.Workspace:children()
for i=1,#children do
    if (children[i].Name == "Judoon") then -- 将名称替换为你模型的名称。
        table.insert(everything, children[i]:clone())
        table.insert(names, children[i].Name)
    end
end

function regen()
    for i=1,#everything do
        game.Workspace:findFirstChild(names[i]):remove() -- 不要乱搞这些东西。
        new_thing = everything[i]:clone()
        new_thing.Parent = game.Workspace
        new_thing:makeJoints()
    end
end

function onClicked()
  if Judoon:FindFirstChild("Judoon"):GetState() == Enum.HumanoidStateType.Dead then
     regen()
  end
end
        wait(15)-- 必须等待的时间,直到再生按钮再次可用。

        script.Parent.BrickColor = BrickColor.new(104)

        debounce = false
end

 script.Parent.ClickDetector.MouseClick:connect(onClicked)

-- 这个 regen 按钮由 andymewborn 制作,希望你喜欢(d)。

  [1]: https://i.stack.imgur.com/HhLo3.png

原文链接 https://stackoverflow.com/questions/60833200

点赞
stackoverflow用户12839543
stackoverflow用户12839543

以下是中文翻译,保留原有的 markdown 格式:

--[[
 1. 把这个脚本放在按钮对象里面
 2. 重命名 modelname
 3. model 必须是 Workspace 的子对象
--]]
 
button = script.Parent
modelname = "Pk" -- 模型名称
model = game.Workspace:FindFirstChild(modelname) -- 初始模型
backup = model:Clone() -- 克隆模型备份用来恢复

function Regen()
    local Old = game.Workspace:FindFirstChild(modelname)
    Old:Destroy() -- 删除原有模型
    local New = backup:Clone()
    model = New -- 替换为新模型
    New.Parent = workspace
    New:MakeJoints() -- 使新模型的所有关节都起作用
end

function onClicked()
    if button.BrickColor == BrickColor.new("Bright violet") then
        if model:FindFirstChild("Humanoid") ~= nil then
            if model.Humanoid:GetState() == Enum.HumanoidStateType.Dead then
                Regen() -- 生成新模型
                print("已删除并且重新生成新模型。")
            end
        end
        button.Regen:Play() -- 播放回归特效
        button.BrickColor = BrickColor.new("Really black") -- 按钮变黑色
        wait(3)
        button.BrickColor = BrickColor.new("Bright violet") -- 按钮恢复原有颜色
    end
end

button.ClickDetector.MouseClick:Connect(onClicked) -- 连接按钮的点击事件
2020-03-24 19:21:17