首页 > 解决方案 > 我怎样才能使人形生物可被杀死并重生?(罗布乐思)

问题描述

标题。我找到的所有教程都只解释了如何制作人体模型,而不是如何让它可以杀死。我已将人形机器人的生命值和最大生命值设置为 100,它会显示生命值条,但它不会受到伤害。谢谢!

标签: roblox

解决方案


这取决于人形机器人从哪里受到伤害。如果它受到不支持 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);

这应该可以使人形机器人受到伤害或杀死它。您也可以使用这些方法杀死其他玩家,因为我们使用远程来对付本地人。

希望我的回答有帮助!


推荐阅读