【问题标题】:Attempt to index boolean with HumanoidRootPart尝试使用 HumanoidRootPart 索引布尔值
【发布时间】:2020-12-25 13:37:46
【问题描述】:

我将这些代码行放入我为僵尸游戏制作的模块脚本中,专门用于放入具有不同僵尸的波浪结构:

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

如何解决?

【问题讨论】:

标签: lua roblox


【解决方案1】:

== 运算符是一个问题:“这两件事是否相等?”

local clone = trollanoid:Clone().Parent == workspace.Zombies 行在问一个问题,“这个克隆的 trollanoid 是在工作区的僵尸文件夹中吗?”并将答案保存在cloned 变量中。

克隆对象,将其添加到世界中,并将克隆存储到变量中...您试图在一行中做太多事情。要解决您的问题,只需隔开您的代码即可。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-02
    • 1970-01-01
    • 2021-12-12
    • 1970-01-01
    • 2014-06-16
    • 2016-12-27
    • 2016-02-16
    相关资源
    最近更新 更多