Я пытаюсь создать игру, которая позволяет игрокам проверять аватар любого другого игрока, сидя на указанном c месте и беседуя с его UserId
или именем пользователя, но когда пользователь вводит имя пользователя, функция всегда возвращает Instance
, что раздражает. Тем не менее, 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
Сценарий на стороне клиента работает хорошо, и я получаю Меню проверки аватара для ROBLOX
, когда я чата 1
в кресле, но когда я общаюсь ROBLOX
в Председатель, я получаю Меню проверки аватара для Instance
или nil
. Есть ли какой-нибудь возможный способ исправить эту ошибку?