如何使类人动物可杀死,并使其重生? (Roblox)

时间:2018-08-27 11:28:12

标签: roblox

标题。我发现的所有教程仅说明如何制作人体模型,而不说明如何使其可杀死。我已将类人生物的“生命值”和“最大生命值”设置为100,并且显示了生命值栏,但它不会受到伤害。 谢谢!

1 个答案:

答案 0 :(得分:0)

这取决于人形生物从何处受到伤害。如果它从不支持FE的LocalScript受到损害,那么人形生物将不会受到损害。

如果您要使人形生物受到伤害或立即杀死它,可以使用以下方法:

即时杀死(来自非LocalScript)

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);

受到了一定程度的损害(来自非LocalScript)

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);

应该这样做,以使人形生物受到伤害或杀死它。您也可以使用这些方法杀死其他玩家,因为我们对本地人使用远程控制。

希望我的回答有帮助!