【问题标题】:Error with getting TextBox data and manipulating it - CLOSED -获取 TextBox 数据并对其进行操作时出错 - 已关闭 -
【发布时间】:2020-08-18 10:12:47
【问题描述】:

在开始之前,我会说控制台中没有任何类型的错误消息。无论如何,我一直在尝试制作一个用户工具游戏,玩家可以在其中查看他们的头像,看起来像他们等等。它曾经在默认的 Roblox 聊天中运行良好,但由于它得到了审核,我制作了一个“聊天栏” “为了我的游戏。但是,现在只有其中一个函数有效(AvatarInspectMenu 带有 UserId,而不是用户名)。自己看看吧:

-- client script
local Players=game:GetService("Players")
local Player=Players.LocalPlayer
local StarterGui=game:GetService("StarterGui")
local GuiService=game:GetService("GuiService")
local Rep=game:GetService("ReplicatedStorage")
repeat wait(0.1) until Player.Character
local h=Player.Character:WaitForChild("Humanoid")
StarterGui:SetCore("TopbarEnabled",false)
local ChatBar=Player.PlayerGui:WaitForChild("ScreenGui").Frame.BoxFrame.Frame.ChatBar
GuiService:SetInspectMenuEnabled(false)
local CS=game:GetService("ContextActionService")
CS:BindAction("Chat Focus",function()
    ChatBar:CaptureFocus()
end,false,Enum.KeyCode.Slash)
function ID(str)
    if tonumber(str)~=nil then
        return tonumber(str)
    else
        return Rep.Idify:InvokeServer(str)
    end
end
ChatBar.FocusLost:Connect(function(entr)
    if not entr then return end
    ChatBar:ReleaseFocus(true)
    local m=ChatBar.Text
    ChatBar.Text=""
    if m=="!reset" then
        Rep.Desc:InvokeServer(Player.UserId)
    end
    if h.Sit then
        if #string.split(m," ")==1 then
            local id=ID(m)
            if h.SeatPart.Name=="AvatarInspectMenu" then
                GuiService:InspectPlayerFromUserId(id)
            end
            if h.SeatPart.Name=="Become" then
                local Desc=Rep.Desc:InvokeServer(id)
                h.Sit=false
            end
            if h.SeatPart.Name=="Tep" then
                local P,J=Rep.Join:InvokeServer(id)
                if not (P and J) then return end
                game:GetService("TeleportService"):TeleportToPlaceInstance(P,J,Player)
            end
        end
    end
end)

-- server-side script
local cache={}
local rep=game:GetService("ReplicatedStorage")
rep.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)
    if not id then return 156 end
    cache[n]=id
    return id
end
local dcs={}
rep.Desc.OnServerInvoke=function(p,n)
    if not dcs[n] then
        pcall(function()
            dcs[n]=game:GetService("Players"):GetHumanoidDescriptionFromUserId(n)
        end)
    end
    p.Character.HumanoidRootPart.CFrame=CFrame.new(0,10,0)
    if not dcs[n] then
        p.Character.Humanoid:ApplyDescription(game:GetService("Players"):GetHumanoidDescriptionFromUserId(156))
        return false
    else
        p.Character.Humanoid:ApplyDescription(dcs[n])
        return true
    end
end
rep.Join.OnServerInvoke=function(_,n)
    local id,jb=nil
    pcall(function()
        id,jb=game:GetService("TeleportService"):GetPlayerPlaceInstanceAsync(n)
    end)
    if id and jb then return id, jb else return nil end
end

我查看了代码,但似乎找不到任何问题(当然,除了在 Studio 中尝试传送时没有错误消息)。帮助将不胜感激!

编辑:此代码功能齐全。无需更多帮助! :D

【问题讨论】:

  • 我测试了 AvatarInspectMenu 和成为,它适用于我与这两个脚本。我唯一要做的就是在结尾添加一个缺失的“结尾”。
  • 你在哪里添加了end?我似乎找不到在哪里。
  • 最后 ;) -- 服务器脚本中最后一个 if 语句中缺少它。
  • @Night94 哦!我没有注意到:) 但是,它仍然不起作用。 :c

标签: lua roblox


【解决方案1】:

如果没有错误,那么它可以工作,也许你错过了一些没有被调用的东西,尝试在函数中添加一些打印以查看它是否打印。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多