尝试用 HumanoidRootPart 索引布尔型变量

我在为我的僵尸游戏制作的模块脚本中插入了以下代码行,特别是为了插入包含不同僵尸的波结构:

local module = {}

wavepause = game.ReplicatedStorage.Values.WavePauseLength.Value
trollanoid = game.ReplicatedStorage.Trollanoid
spawnpoints = workspace.Test1.Spawns:GetChildren()

function trollanoidsummon()
    local chosenspawn = spawnpoints[math.random(#spawnpoints)]
    local clone = trollanoid:Clone().Parent == workspace.Zombies
    clone.HumanoidRootPart.Position = chosenspawn.Position
end

module.Wave1 = function()
    trollanoidsummon()
    wait(1)
    trollanoidsummon()
    wait(1)
    trollanoidsummon()
    wait(1)
    trollanoidsummon()
end

return module

然后得到了以下回复:

 22:00:27.837  ServerScriptService.WaveModule:10: attempt to index boolean with
'HumanoidRootPart'  -  Server  -  WaveModule:10

如何解决?

点赞
用户2860267
用户2860267

== 操作符被用来提出问题:"这两个东西是否相等?"

local clone = trollanoid:Clone().Parent == workspace.Zombies 提出问题:"这个克隆的 trollanoid 是否在工作区的 zombies 文件夹中?" 并将答案保存到 cloned 变量中。

复制对象,将其添加到世界中,并将克隆存储到一个变量中…你试图在一行中做太多的事情。为了解决你的问题,只需将代码分成几行。

function trollanoidsummon()
    local chosenspawn = spawnpoints[math.random(#spawnpoints)]
    local clone = trollanoid:Clone()
    clone.Parent = workspace.Zombies
    clone.HumanoidRootPart.Position = chosenspawn.Position
end
2020-12-25 05:37:46