参数1丢失或为空

我正在制作一个塔防游戏,但它一直显示参数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("缺少:", Name)
  end
end

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

return Tower

原文链接 https://stackoverflow.com/questions/70712899

点赞
stackoverflow用户2858170
stackoverflow用户2858170

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

SpawnTowerEvent.OnServerEvent:Connect(Tower.Spawn)

你调用了Tower.Spawn而没有任何参数。因此你调用了FindFirstChild(nil)导致了观察到的错误。此外它没有返回一个函数值。

2022-01-14 16:03:32