复制存储时参数 1 缺失或为零

问题描述 投票:0回答:1
      local Ally = {}
local PhysicsService = game:GetService("PhysicsService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PlaceTowerEvent = ReplicatedStorage:WaitForChild("Event").PlaceTower
wait(1)

function Ally.Spawn(player,name,cframe)
    local AllyExists = game.ReplicatedStorage.Towers:FindFirstChild(name)
    if AllyExists then
        
        local TowerClone = AllyExists:Clone()
        TowerClone.HumanoidRootPart.CFrame = cframe
        TowerClone.Parent = workspace.Allies
        AllyExists.HumanoidRootPart:SetNetworkOwnership(nil)
        
        for i, v in pairs(TowerClone:GetChildren()) do
            if v:IsA("BasePart") then
                v.CollisionGroup = "Ally"
            end
        end
    else
        warn("Tower does not exist")
    end
end

wait(1)
PlaceTowerEvent.OnServerEvent:Connect(Ally.Spawn)
return Ally

线上

ReplicatedStorage.Towers:FindFirstChild(name)
,上面写着
argument 1 missing or nil
。我尝试查看其他脚本并重新观看教程,但一切似乎都很好。我不知道如何解决这个问题,所以请帮忙!

roblox
1个回答
0
投票

很有可能您没有正确地将数据从客户端发送到服务器。因为它可能返回参数“name”和“cframe”nil。

重现您的问题的示例; 客户:

remoteEvent:FireServer()
remoteEvent:FireServer(nil, nil)

服务器:

remoteEvent.OnServerEvent:Connect(function(player, param1, param2)
    print(param1, param2) -- nil, both times
end)

您可以检查客户端通过远程发送到服务器的内容 它应该导致发送的参数为零,或者您发送的对象是可变的并且仅存在于客户端上,这意味着服务器没有对该仅客户端对象的引用。

要解决此问题,您只需诊断客户端上的参数即可。

© www.soinside.com 2019 - 2024. All rights reserved.