Lua &引用;无法将值强制转换为对象";错误消息

Lua &引用;无法将值强制转换为对象";错误消息,lua,roblox,Lua,Roblox,所以我在使用一个远程函数,正如最后所看到的,由于某种原因,一个变量的正常赋值是不起作用的,它给了我一个错误消息,“无法将值转换为对象”,怎么了 local storeEvent = script.Parent.Parent.OpenStore local slotNum = 1 script.Parent.Touched:Connect(function (hit) if game.Players:GetPlayerFromCharacter(hit.Parent) then

所以我在使用一个远程函数,正如最后所看到的,由于某种原因,一个变量的正常赋值是不起作用的,它给了我一个错误消息,“无法将值转换为对象”,怎么了

local storeEvent = script.Parent.Parent.OpenStore
local slotNum = 1
script.Parent.Touched:Connect(function (hit)
    if game.Players:GetPlayerFromCharacter(hit.Parent) then
        storeEvent:InvokeClient(slotNum)
    end
end)
并连接到另一个脚本:

script.Parent.OnInvoke:Connect(function (slot)
    local StoreArrows = game.ReplicatedStorage.StoreArrows
    StoreArrows.SlotNum.Value = slot
    local cam = game.Workspace.Camera
    local storeButtons = script.Parent
    local camNum = game.ReplicatedStorage.StoreArrows.CamNum.Value
    local camNumInst = game.Workspace.CamStorage:WaitForChild("Cam-"..camNum)
    cam.CameraType = Enum.CameraType.Scriptable
    cam.CFrame = camNumInst.CFrame
    local clonedStoreButtons = StoreArrows:Clone()
    clonedStoreButtons.Parent = player.PlayerGui.ScreenGui
end)

请记住,许多客户端一次连接到服务器。所以当你调用一个函数时,你必须告诉它在哪个客户机上调用它。
InvokeClient
的第一个参数应该是播放器,这就是为什么错误告诉您它无法将
slotNum
值强制转换为播放器对象

local storeEvent = script.Parent.Parent.OpenStore
local slotNum = 1
script.Parent.Touched:Connect(function(hit)
    -- check that the thing that we touched is actually a player
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if player then
        -- tell that player to open the store
        storeEvent:InvokeClient(player, slotNum)
    end
end)

请记住,许多客户端一次连接到服务器。所以当你调用一个函数时,你必须告诉它在哪个客户机上调用它。
InvokeClient
的第一个参数应该是播放器,这就是为什么错误告诉您它无法将
slotNum
值强制转换为播放器对象

local storeEvent = script.Parent.Parent.OpenStore
local slotNum = 1
script.Parent.Touched:Connect(function(hit)
    -- check that the thing that we touched is actually a player
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if player then
        -- tell that player to open the store
        storeEvent:InvokeClient(player, slotNum)
    end
end)

错误指向哪一行?发送脚本的第5行我认为这是范围问题。将该行放在第二个脚本的开头,并在函数外部定义该变量<代码>本地storeButtons=脚本。父storeButtons.OnInvoke:Connect(函数(插槽)…错误指向哪一行?发送脚本的第5行我认为这是一个范围问题。将该行放在第二个脚本的开头,并在函数外部定义该变量。
local storeButtons=script.Parent storeButtons.OnInvoke:Connect(函数(插槽)…
我刚才试过了,但现在它什么都不起作用。我看到你将此标记为答案,即使你说它不起作用。你用连接脚本解决了你的问题吗?是的,它有帮助,我现在发现了问题,远程事件没有存储在复制存储中,它现在工作正常。我刚才试过,一个d现在它什么都不做我看到你将此标记为答案,即使你说它不起作用。你用连接脚本解决了问题吗?是的,它有帮助,我现在发现了问题,远程事件没有存储在复制存储中。它现在可以正常工作