【发布时间】:2020-05-03 09:55:52
【问题描述】:
我正在尝试制作一款游戏,允许玩家通过坐在特定座位上并与他们的 UserId 或用户名聊天来检查任何其他玩家的头像,但是当用户输入用户名时,该函数总是返回 @987654322 @,这很烦人。但是,UserId 有效。这是我的代码:
-- client-side script
local Players=game:GetService("Players")
local Player=Players.LocalPlayer
local GuiService=game:GetService("GuiService")
local Rep=game:GetService("ReplicatedStorage")
repeat wait(0.1) until Player.Character
local h=Player.Character:WaitForChild("Humanoid")
GuiService:SetInspectMenuEnabled(false)
Player.Chatted:Connect(function(m)
if h.Sit then
if #string.split(m," ")==1 then
if tonumber(m)~=nil then
if h.SeatPart.Name=="AvatarInspectMenu" then
local id=tonumber(m)
GuiService:InspectPlayerFromUserId(id)
end
else
if h.SeatPart.Name=="AvatarInspectMenu" then
local id=Rep.Idify:InvokeServer(m)
GuiService:InspectPlayerFromUserId(id)
end
end
end
end
end)
--server-side script
local cache={}
game:GetService("ReplicatedStorage").Idify.OnServerInvoke=function(n)
if cache[n] then return cache[n] end
local player=game.Players:FindFirstChild(n)
if player then
cache[n]=player.UserId
return player.UserId
end
local id
pcall(function ()
id = game.Players:GetUserIdFromNameAsync(n)
end)
cache[n] = id
return id
end
客户端脚本运行良好,当我在椅子上聊天 1 时,我得到了 ROBLOX 的 Avatar Inspect Menu,但是当我在椅子上聊天 ROBLOX 时,我得到一个 Avatar Inspect Menu Instance,或nil。有没有办法解决这个错误?
【问题讨论】: