Roblox Studio: 创建隐藏UI的音乐播放器
local ScreenGui = Instance.new('ScreenGui') ScreenGui.Name = 'MusicPlayer' local Frame = Instance.new('Frame') Frame.Position = UDim2.new(0.5, -50, 0.5, -25) Frame.Size = UDim2.new(0, 100, 0, 90) Frame.BackgroundColor3 = Color3.new(1, 1, 1) Frame.BackgroundTransparency = 0.5 Frame.Active = true Frame.Draggable = true Frame.Parent = ScreenGui
-- 创建文本框 local TextBox = Instance.new('TextBox') TextBox.Size = UDim2.new(1, -20, 0, 30) TextBox.Position = UDim2.new(0, 10, 0, 10) TextBox.PlaceholderText = '输入音乐代码' TextBox.ClearTextOnFocus = false TextBox.Parent = Frame
-- 创建播放按钮 local PlayButton = Instance.new('TextButton') PlayButton.Text = '播放音乐' PlayButton.Size = UDim2.new(1, -20, 0, 30) PlayButton.Position = UDim2.new(0, 10, 1, -40) PlayButton.Parent = Frame
-- 创建展开/隐藏按钮 local HideButton = Instance.new('TextButton') HideButton.Text = '隐藏' HideButton.Size = UDim2.new(0, 50, 0, 20) HideButton.Position = UDim2.new(0, 0, 0, 70) HideButton.Parent = Frame
-- 添加播放器脚本 local MusicPlayer = Instance.new('Sound', game.Workspace) MusicPlayer.Volume = 1 MusicPlayer.Playing = false
PlayButton.MouseButton1Click:Connect(function() local Code = TextBox.Text if Code ~= '' then MusicPlayer.SoundId = 'rbxassetid://'..Code MusicPlayer:Play() end end)
-- 隐藏UI的函数 local function hideUi() for _, child in ipairs(ScreenGui:GetChildren()) do if child ~= HideButton then child.Visible = false end end end
HideButton.MouseButton1Click:Connect(function() hideUi() end)
ScreenGui.Parent = game.Players.LocalPlayer:WaitForChild('PlayerGui')
原文地址: https://www.cveoy.top/t/topic/narX 著作权归作者所有。请勿转载和采集!