我需要一个可以在 Roblox 中启动 GUI 的脚本吗?

发布于 2024-10-08 07:31:12 字数 59 浏览 6 评论 0原文

如何让脚本在触摸砖块时调出商店 GUI?

我应该如何在商店 GUI 中制作“购买”东西?

How do I make a script bring up a shop GUI when a brick is touched?

And how should I make the "buy" stuff in the shop GUI?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

似梦非梦 2024-10-15 07:31:12

您需要自己制作商店界面
但我会给你“GUI Giver”脚本。
注意:您必须将脚本放在程序块/零件内部中。

local GUI = game:GetService("ServerStorage"):WaitForChild("GUI") -- Recommended to place your GUI inside of ServerStorage

script.Parent.Touched:Connect(function(hit)
    local Player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
    if Player then
        if not Player:WaitForChild("PlayerGui"):FindFirstChild(GUI.Name) then
            GUI:Clone().Parent = Player.PlayerGui
        end
    end
end)

You will be needing to make that Shop Interface yourself,
but i will give you the "GUI Giver" script.
Note: You must put the Script Inside the Brick/Part.

local GUI = game:GetService("ServerStorage"):WaitForChild("GUI") -- Recommended to place your GUI inside of ServerStorage

script.Parent.Touched:Connect(function(hit)
    local Player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
    if Player then
        if not Player:WaitForChild("PlayerGui"):FindFirstChild(GUI.Name) then
            GUI:Clone().Parent = Player.PlayerGui
        end
    end
end)
暖树树初阳… 2024-10-15 07:31:12

编写一个脚本,将砖块的“Touched”事件连接到使用游戏的“getPlayerFromCharacter”方法的函数。玩家找到玩家,然后将 GUI 插入玩家的“PlayerGui”中。例如:

function newGUI()
    --enter something that makes a shop GUI then at the end returns the 'ScreenGui' it's in.
end

script.Parent.Touched:connect(function(hit)
    local player = game.Players:getPlayerFromCharacter(hit.Parent);
    if player ~= nil then
        newGUI().Parent = player.PlayerGui;
    end
end)

Make a script that connects a brick's 'Touched' event to a function which uses the "getPlayerFromCharacter" method of game.Players to find the player then inserts the GUI into the player's "PlayerGui". For example:

function newGUI()
    --enter something that makes a shop GUI then at the end returns the 'ScreenGui' it's in.
end

script.Parent.Touched:connect(function(hit)
    local player = game.Players:getPlayerFromCharacter(hit.Parent);
    if player ~= nil then
        newGUI().Parent = player.PlayerGui;
    end
end)
入画浅相思 2024-10-15 07:31:12

以下代码可用于为玩家提供商店 GUI:

local ShopGui = game.Lighting.ShopGui -- This should be the location of your gui
local ShopPart = workspace.ShopPart -- This should be the shop part

ShopPart.Touched:connect(function(hit)
    if hit.Parent == nil then return end
    if hit.Name ~= "Torso" then return end
    local Player = game.Players:playerFromCharacter(hit.Parent)
    if Player == nil then return end
    if _G[Player] == nil then _G[Player] = {} end
    if _G[Player].ShopGui == nil then
        _G[Player].ShopGui = ShopGui:Clone()
        _G[Player].ShopGui.Parent = Player.PlayerGui
    end
end)

ShopPart.TouchEnded:connect(function(hit)
    if hit.Parent == nil then return end
    local Player = game.Players:playerFromCharacter(hit.Parent)
    if Player == nil then return end
    if _G[Player] == nil then return end
    if _G[Player].ShopGui ~= nil then
        _G[Player].ShopGui:Destroy()
        _G[Player].ShopGui = nil
    end
end)

请注意,“ShopPart”应该是覆盖整个商店区域的一个大部分(最好是不可见的)

然后您还必须构建一个商店 GUI。

在商店 GUI 中,您应该制作文本按钮(或图像按钮),每个按钮都包含以下脚本:

local Cost = 100
local ThingToBuy = game.Lighting.Weapon -- Make sure this is right
script.Parent.MouseButton1Down:connect(function()
    local Player = script.Parent.Parent.Parent.Parent -- Make sure this is correct
    if Player.leaderstats["money"].Value >= Cost then -- Change "money" to anything you want (it     must be in the leaderstats tho)
        Player.leaderstats["money"].Value = Player.leaderstats["money"].Value - Cost
        ThingToBuy:Clone().Parent = Player.Backpack
        -- GuiToBuy:Clone().Parent = Player.PlayerGui
    end
end)

该代码未经测试,因此可能包含错误。而且您可能需要更改的内容比提到的更多。但它应该能让你了解如何制作商店 GUI =)

The following code can be used to give the player the shop gui:

local ShopGui = game.Lighting.ShopGui -- This should be the location of your gui
local ShopPart = workspace.ShopPart -- This should be the shop part

ShopPart.Touched:connect(function(hit)
    if hit.Parent == nil then return end
    if hit.Name ~= "Torso" then return end
    local Player = game.Players:playerFromCharacter(hit.Parent)
    if Player == nil then return end
    if _G[Player] == nil then _G[Player] = {} end
    if _G[Player].ShopGui == nil then
        _G[Player].ShopGui = ShopGui:Clone()
        _G[Player].ShopGui.Parent = Player.PlayerGui
    end
end)

ShopPart.TouchEnded:connect(function(hit)
    if hit.Parent == nil then return end
    local Player = game.Players:playerFromCharacter(hit.Parent)
    if Player == nil then return end
    if _G[Player] == nil then return end
    if _G[Player].ShopGui ~= nil then
        _G[Player].ShopGui:Destroy()
        _G[Player].ShopGui = nil
    end
end)

Note that "ShopPart" should be a big part that cover the whole shop area (preferable invisible)

Then you also have to build a shop gui.

In the shop gui you should make TextButtons (or image buttons) that each contains the following script:

local Cost = 100
local ThingToBuy = game.Lighting.Weapon -- Make sure this is right
script.Parent.MouseButton1Down:connect(function()
    local Player = script.Parent.Parent.Parent.Parent -- Make sure this is correct
    if Player.leaderstats["money"].Value >= Cost then -- Change "money" to anything you want (it     must be in the leaderstats tho)
        Player.leaderstats["money"].Value = Player.leaderstats["money"].Value - Cost
        ThingToBuy:Clone().Parent = Player.Backpack
        -- GuiToBuy:Clone().Parent = Player.PlayerGui
    end
end)

The code ain't tested, so it might contain errors. And you might need to change more stuff than mentioned. But it should give you an idea on how to make the shop gui =)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文