如何修复未生成的NPC [英] How to fix NPCs not spawning

查看:75
本文介绍了如何修复未生成的NPC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在ModuleScript中编码了一些功能,以便由另一个脚本执行.这是代码

I coded out some functions in a ModuleScript to be executed by another script. Here is the code

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出现在地图上,但是我在输出中得到了这个错误:

What I expected was the NPC trollanoids to appear on the map, but instead I got this error in the output:

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

我不知道我做错了什么,请帮助我解决此问题.感谢您的帮助

I dont know what I did wrong, please help me fix this. Any help is appreciated

推荐答案

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

You are calling an object. Like mentioned above, you can only call functions and objects with __call metamethod.

尝试一下:

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

要使用该模块,请执行以下操作:

To use the module you would do this:

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

我做了一些小改动.让我知道您是否需要任何帮助:)

I made a few minor changes. Let me know if you need help with any :)

这篇关于如何修复未生成的NPC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆