ZBLOG

22:27:05.013 Players.lryghbbxzs.PlayerGui.ScreenGui.TextButton.Script:11: attempt to index nil with 'PlayerGui' - Studio

抱歉,上述代码有一个错误。在使用player.PlayerGui之前,需要先确认PlayerGui是否存在。你可以修改代码如下:

local player = game.Players.LocalPlayer

-- 创建新窗口
local function createWindow(title, onClose)
    local window = Instance.new("ScreenGui")
    local frame = Instance.new("Frame")
    local closeButton = Instance.new("TextButton")

    window.Name = "Window"
    window.Parent = player.PlayerGui or game.StarterGui -- 先检查PlayerGui是否存在,不存在则使用StarterGui
    frame.Name = "Frame"
    frame.Parent = window
    closeButton.Name = "CloseButton"
    closeButton.Parent = frame
    closeButton.Text = "关闭"

    -- 设置窗口样式和位置
    -- ...

    -- 关闭窗口时执行回调函数
    closeButton.MouseButton1Click:Connect(function()
        window:Destroy()
        if onClose then
            onClose()
        end
    end)

end

-- 点击TextButton时创建新窗口并获取服务器玩家列表供选择
script.Parent.MouseButton1Click:Connect(function()
    
	createWindow("选择举报的玩家", function()
		-- 在这里添加“确定”按钮点击后的逻辑代码(打印举报内容等)
		
		print("举报成功 正在人工审核")
		
		createWindow("举报成功", nil)
		
	end)
	
end)

这样修改后应该能够解决该错误。请确保脚本中其他部分也是正确的,并根据实际需求进行进一步的开发和完善。


内容由零声教学AI助手提供,问题来源于学员提问

本站部分文章来源于网络,版权归原作者所有,如有侵权请联系站长删除。
转载请注明出处:http://sdn.0voice.com/?id=2835

分享:
扫描分享到社交APP
上一篇
下一篇
发表列表
游客 游客
此处应有掌声~
评论列表

还没有评论,快来说点什么吧~

联系我们

在线咨询: 点击这里给我发消息

微信号:3007537140

上班时间: 10:30-22:30

关注我们
x

注册

已经有帐号?