【问题标题】:How to fix NPCs not spawning如何修复NPC不生成
【发布时间】:2021-04-02 19:25:17
【问题描述】:

我在 ModuleScript 中编写了一些函数,以便由另一个脚本执行。这是代码

local module = {}

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

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

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

return module

我期望 NPC trollanoids 出现在地图上,但我在输出中得到了这个错误:

17:50:19.011  ServerScriptService.WaveModule:14: attempt to call a Instance 
value  -  Server  -  WaveModule:14

我不知道我做错了什么,请帮我解决这个问题。任何帮助表示赞赏

【问题讨论】:

    标签: lua roblox


    【解决方案1】:

    错误信息告诉你出了什么问题:

    您正在尝试call 一个对象。您可以在 Lua 中调用的唯一内容是 函数 和带有 __call 元方法的对象。

    【讨论】:

      【解决方案2】:

      你正在调用一个对象。如上所述,您只能使用 __call 元方法调用函数和对象。

      试试这个:

      local module = {}
      
      wavepause = game.ReplicatedStorage.Values.WavePauseLength
      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.CFrame = chosenspawn.CFrame
      end
      
      module:SpawnNPC(amount, threshold)
          threshold = threshold or 1
          amount = amount or 4
          for i = 1, amount do
              if wavepause.Value then break end;
              trollanoidsummon()
              wait(threshold)
          end
      end
      
      return module
      

      要使用该模块,您可以这样做:

      local spawner = require(modulescriptpath);
      spawner:SpawnNPC(5, 1);
      

      我做了一些小改动。如果您需要任何帮助,请告诉我:)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-07-15
        • 1970-01-01
        • 2020-01-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多