"Unable to cast value to Object" 错误信息
"Unable to cast value to Object" error message
所以我正在使用远程函数,如最后所见,由于某种原因,变量的正常赋值不起作用,它给我错误消息,“无法将值转换为对象, 怎么了?
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)
请记住,许多客户端同时连接到服务器。因此,当您调用 RemoteEvent's InvokeClient 函数时,您必须告诉它 在哪个 客户端上调用它。 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)
所以我正在使用远程函数,如最后所见,由于某种原因,变量的正常赋值不起作用,它给我错误消息,“无法将值转换为对象, 怎么了?
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)
请记住,许多客户端同时连接到服务器。因此,当您调用 RemoteEvent's InvokeClient 函数时,您必须告诉它 在哪个 客户端上调用它。 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)