bad argument #3 to 'Value' (string expected, got Object) - 如何解决?

我查看了许多其他问题和它们的答案,但我似乎还是无法解决这个错误消息。我正在编写一个脚本,允许一个玩家改变另一个玩家的面孔。由于新的ROBLOX更新它是FE兼容的,因此我将放置本地脚本和服务器脚本,即使错误在服务器脚本中也是如此。

Local Script:

plr = script.Parent.Parent.Parent.NameInput.Text

script.Parent.MouseButton1Click:Connect(function()
    script.Parent.RemoteEvent:FireServer(plr)
end)

Server Script:

faceid = script.Parent.FaceID.Value

script.Parent.RemoteEvent.OnServerEvent:Connect(function(plr)
    script.Parent.PName.Value = plr
    local plrname = script.Parent.PName.Value
    print (plrname)
    game.Players[script.Parent.PName.Value].Character.Face.Texture = faceid
end)

Hierarchy: 这是我正在创建的GUI的层次结构图像

错误消息: 这是当我按下名为“ One” 的“ Test Face” 按钮时收到的错误图像。

服务器脚本有点混乱,因为我尝试了一些不同的方法来解决这个错误,因此,如果您认为我可以更改任何内容或添加/删除任何内容,我会感激反馈。然而,当前的主要问题是我在第4行遇到的错误。之前还有一个错误,说“ bad argument#2 to ?(期望字符串,得到Object)”,但我想首先解决这个问题。如果尝试帮助我的人认为必要,也会欢迎对脚本的帮助。

提前感谢您的帮助, Rohan

点赞
用户10041320
用户10041320

相比使用 plr ,你应该使用 plr.Name 来获取玩家的名字。这样,你会告诉系统你需要的是玩家的名字而不是对象。

faceid = script.Parent.FaceID.Value

script.Parent.RemoteEvent.OnServerEvent:Connect(function(plr)
    script.Parent.PName.Value = plr.Name -- 这里进行了编辑
    local plrname = script.Parent.PName.Value
    print (plrname)
    game.Players[script.Parent.PName.Value].Character.Face.Texture = faceid
end)
2018-08-07 10:54:02