参数 1 缺失或为零

argument 1 missing or nil

我正在制作塔防游戏,但它一直说参数 1 丢失或为零 当我尝试生成塔时 这是一个模块脚本 (第 11 行错误)

local PhysicsServive = game:GetService("PhysicsService")
local ServerStorage = game:GetService("ServerStorage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PhysicsService = game:GetService("PhysicsService")
local events = ReplicatedStorage:WaitForChild("Events")
local Tower = {}
local SpawnTowerEvent = events:WaitForChild("SpawnTower")


function Tower.Spawn(player, Name, CFrame)
   local towerExists = ReplicatedStorage.Towers:FindFirstChild(Name)
    if towerExists then
    local newTower = towerExists:Clone()
    newTower.HumanoidRootPart.CFrame = CFrame
    newTower.Parent = workspace.Towers
    newTower.HumanoidRootPart:SetNetworkOwner(nil)
    for i, object in ipairs(newTower:GetDescendants()) do
        if object:IsA("BasePart") then
            PhysicsService:SetPartCollisionGroup(object, "Tower")
            object.Material = Enum.Material.ForceField
        end
    end

 else
    warn("Missing:", Name)
  end
end

SpawnTowerEvent.OnServerEvent:Connect(Tower.Spawn())

return Tower
SpawnTowerEvent.OnServerEvent:Connect(Tower.Spawn())

Connect 需要函数值,而不是函数调用(除非该函数调用解析为函数值)。删除调用运算符 ().

SpawnTowerEvent.OnServerEvent:Connect(Tower.Spawn) 

您调用 Tower.Spawn 时没有任何参数。因此,您调用 FindFirstChild(nil) 会导致观察到的错误。 它也不是 return 函数值。