【发布时间】:2020-11-14 08:26:19
【问题描述】:
所以我使用了一个远程函数,如最后所示,由于某种原因,一个变量的正常赋值不起作用,它给我一个错误消息,“无法将值转换为对象”怎么了?
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)
【问题讨论】:
-
错误指向的行是什么?
-
发送脚本的第 5 行
-
我认为这是一个范围问题。将该行放在第二个脚本的开头,并在函数之外定义该变量。
local storeButtons = script.Parent storeButtons.OnInvoke:Connect(function (slot)...