Lua Roblox 角色死亡重生
2020-3-24 21:35:29
收藏:0
阅读:152
评论:1
如何使这段代码工作?当我点击墙壁时,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
点赞
评论区的留言会收到邮件通知哦~
推荐文章
- 如何在roblox studio中1:1导入真实世界的地形?
- 求解,lua_resume的第二次调用继续执行协程问题。
- 【上海普陀区】内向猫网络招募【Skynet游戏框架Lua后端程序员】
- SF爱好求教:如何用lua实现游戏内调用数据库函数实现账号密码注册?
- Lua实现网站后台开发
- LUA错误显式返回,社区常见的规约是怎么样的
- lua5.3下载库失败
- 请问如何实现文本框内容和某个网页搜索框内容连接,并把网页输出来的结果反馈到另外一个文本框上
- lua lanes多线程使用
- 一个kv数据库
- openresty 有没有比较轻量的 docker 镜像
- 想问一下,有大佬用过luacurl吗
- 在Lua执行过程中使用Load函数出现问题
- 为什么 neovim 里没有显示一些特殊字符?
- Lua比较两个表的值(不考虑键的顺序)
- 有个lua简单的项目,外包,有意者加微信 liuheng600456详谈,最好在成都
- 如何在 Visual Studio 2022 中运行 Lua 代码?
- addEventListener 返回 nil Lua
- Lua中获取用户配置主目录的跨平台方法
- 如何编写 Lua 模式将字符串(嵌套数组)转换为真正的数组?
以下是中文翻译,保留原有的 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) -- 连接按钮的点击事件