为什么在远程事件中运行此函数时会出现“无法将值转换为对象”的错误?

当我运行此代码时,会出现错误,提示“无法将值转换为对象”,出现在第49行(giveOre:FireClient(oreType.Value))上,尽管oreType被分类为StringValue。

    function mineOre(plr,target,objTool)
if not target.ClassName == "Model" then --// try to find if target is valid, else set target as target's parent (confusing prob for someone)
    target = target.Parent
end

local oreFolder = target:FindFirstChild("OreStats"if oreFolder then
    --// Identify ore key vals
    local oreHP = oreFolder:FindFirstChild("OreHP")
    local oreLVL = oreFolder:FindFirstChild("OreLVL")

    local toolLVL = objTool.stats:FindFirstChild("LVL"if toolLVL and oreLVL then
        local _math = toolLVL.Value - oreLVL.Value
        if _math >= 0 then
            local toolDMG = objTool.stats:FindFirstChild("DMG")
            oreHP.Value = oreHP.Value - toolDMG.Value

            --// Check if oreHP is 0 or less
            if oreHP.Value <= 0 then
                local oreType = oreFolder:FindFirstChild("OreType")
                local giveOre = plr.Backpack:FindFirstChild("GiveORE")
                giveOre:FireClient(oreType.Value) --// Give the player the ore.

                pcall(function()
                    delay(0.1, function() target:Destroy() end)
                end)
            end
        end
    end
end
    end

这是客户端触发的事件,如果需要可以使用

    function findSec()
local secs = {}

local toSearch = game:GetService("Players").LocalPlayer.PlayerGui:WaitForChild("Backpack").Area.Inv:GetChildren()
for i,v in pairs(toSearch) do
    local ocu = v:FindFirstChild("Occupied"local lock = v:FindFirstChild("Locked"if ocu.Value == false and lock.Value == false then
        table.insert(secs, v)
    end
end
end

function giveOre(oreType)
local sec = findSec()
local toSet = sec [1]

toSet.Occupied = true
toSet.Locked = true
toSet.Ore = oreType
end

rem.OnClientEvent:connect(function(oreType)
giveOre(oreType)
end)

谢谢。

点赞
用户5831152
用户5831152

记住,RemoteEvent:FireClient() 需要第一个参数是你发送给的客户端。你会因为试图发送一个字符串到程序期望的玩家实例而引发错误。 正确的代码应该是

giveOre:FireClient(plr, oreType.Value)
2018-06-13 15:37:09