roblox - 我怎样才能使人形生物可被杀死并重生?(罗布乐思)
问题描述
标题。我找到的所有教程都只解释了如何制作人体模型,而不是如何让它可以杀死。我已将人形机器人的生命值和最大生命值设置为 100,它会显示生命值条,但它不会受到伤害。谢谢!
解决方案
这取决于人形机器人从哪里受到伤害。如果它受到不支持 FE 的 LocalScript 的伤害,那么 Humanoid 将不会受到伤害。
如果你想让一个人形机器人受到伤害,或者立即杀死它,这里有一些方法:
立即杀死(来自非本地脚本)
local character = nil; -- replace nil with the character
character:BreakJoints();
立即杀死(来自 LocalScript)
在本地脚本中:
local character = game:service("Players").LocalPlayer.Character -- replace this to the character. if you don't replace it, it will kill your character.
local rep = game:service("ReplicatedStorage");
local event = rep:WaitForChild("killEvent");
event:FireServer(character);
在普通脚本中:
local rep = game:service("ReplicatedStorage");
local ev = Instance.new("RemoteEvent",rep);
ev.Name = "killEvent";
ev.OnServerEvent:connect(function(plr, char)
if not char then char = plr.Character end;
char:BreakJoints();
end);
受到一定程度的伤害(来自非本地脚本)
local character = nil; -- replace nil with the character
local humanoid = character:WaitForChild("Humanoid");
local damage = 50; -- Change this to the damage you want the humanoid to take
humanoid:TakeDamage(damage);
受到一定程度的伤害(来自 LocalScript)
在本地脚本中:
local rep = game:service("ReplicatedStorage");
local event = rep:WaitForChild("damageEvent");
local character = game:service("Players").LocalPlayer.Character; -- replace this to the character. if you don't change it, it will automatically damage your character.
local humanoid = character:WaitForChild("Humanoid");
local damage = 50; -- Change this to the damage you want the player to take
event:FireServer(humanoid, damage);
在普通脚本中:
local rep = game:service("ReplicatedStorage");
local event = Instance.new("RemoteEvent", rep);
event.Name = "damageEvent";
event.OnServerEvent:connect(function(player, hum, damage)
if not hum then hum = player.Character.Humanoid; end;
hum:TakeDamage(damage);
end);
这应该可以使人形机器人受到伤害或杀死它。您也可以使用这些方法杀死其他玩家,因为我们使用远程来对付本地人。
希望我的回答有帮助!
推荐阅读
- android - 如何在颤动中使用风味?
- apache-spark - 使用 Spark 或 Hive 控制台从 avro 表读取异常 - 无法从文件模式获取 varchar 字段的 maxLength 值:“字符串”
- php - 如何在 oracle PHP 中与邮件服务器建立连接?
- c# - 用 Modal 替换 ASP.NET 身份登录和注册页面,但收到 InvalidOperationException
- python - 绘制不平衡的数据集
- ios - 在 iOS 应用程序和 Webview 中使用 MSAL 进行单点登录
- r - 德国引号在 tinytex/rmarkdown 中损坏 - 即使使用包 `csquotes`
- json - 具有基于问题的分数的问答游戏的数据结构
- ruby-on-rails - 如何在不创建实例组的情况下管理 GCE VM 实例中的多个请求?
- javascript - 当它应该未定义时,JavaScript 绑定将第二个参数设置为等于第一个参数?