首页 > 解决方案 > Lua Roblox重生角色死了

问题描述

我应该如何使这段代码工作?Judoon 角色必须在我点击墙壁时重生(重生),但仅在他死时。[![Regenerate][1]][1] 当我点击墙壁时,我的 Judoon 角色必须重生,但仅在他死了。

另外,我怎样才能引入 Regen Button,脚本,与 Judoon 模型分开,但它应该可以工作。如果将脚本 Regen 放入 Workspace,与 Judoon 文件夹分开,它将不起作用。

   local box = script.Parent


local debounce = false

-- DO NOT GROUP THIS WITH YOUR MODEL!

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

local children = game.Workspace:children()
for i=1,#children do
    if (children[i].Name == "Judoon") then -- Replace the name with your models's name.
        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() -- Dont mess with this stuff.
        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)-- This is how long it takes untill the regen button will work again.

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


        debounce = false
end

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

--This regen button was made by andymewborn,hope you like(d) it!

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

标签: lua

解决方案


你可以做这样的事情,如果类人生物死了然后再生。

function onClicked()  
  if Judoon:FindFirstChild("Judoon"):GetState() == Enum.HumanoidStateType.Dead then
     regen()
  end
end

新编辑:

--[[
    1. Put this script inside the button
    2. Rename the modelname
    3. The model must be a child of Workspace
--]]
button = script.Parent
modelname = "Pk" -- Model name
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 changes made here
    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("removed and added")
            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)

推荐阅读