lua - 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
解决方案
你可以做这样的事情,如果类人生物死了然后再生。
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)
推荐阅读
- excel - 尝试在 Excel 中创建自定义搜索按钮
- css - 向下滚动时隐藏,向上滚动时显示
- tensorflow - 如何使用 train_image_classifier.py 训练性别和年龄
- jquery - 在表单中选定控件的 jquery 事件上显示标签(HTMLHelper)
- node.js - firebase-functions,TypeError:无法读取未定义的属性“onRequest”
- python - 将 numpy.float64 类型转换为 int 的 Tensorflow 问题
- python - 如何在情感分析中添加混淆矩阵和k-fold 10折
- ios - 我如何获取数据并在 viewdidload 中使用它......不在函数内部?
- ios - 什么 UIKit 控件在用户组搜索/作曲家中被子类化?(iMessage,社交媒体群聊)
- java - 问题:无法解析构造函数 CSVPrinter