【问题标题】:I need a Script that brings up a Gui on touch in Roblox?我需要一个在 Roblox 中显示 GUI 的脚本吗?
【发布时间】:2011-05-25 16:39:38
【问题描述】:

如何让脚本在触摸砖块时显示商店 GUI?

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

【问题讨论】:

  • 我们不是来为您编写代码的。也许如果您将问题缩小到您遇到问题的特定领域,那么有人可以指出解决方案。

标签: roblox


【解决方案1】:

您需要自己制作商店界面, 但我会给你“GUI Giver”脚本。
注意:您必须将脚本放在Inside 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)

【讨论】:

    【解决方案2】:

    制作一个脚本,将积木的“Touched”事件连接到一个函数,该函数使用 game.Players 的“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)
    

    【讨论】:

      【解决方案3】:

      以下代码可用于为玩家提供商店 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 中,您应该制作 TextButtons(或图像按钮),每个按钮都包含以下脚本:

      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 =)

      【讨论】:

        猜你喜欢
        • 2016-05-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-12-26
        • 1970-01-01
        • 2013-12-28
        相关资源
        最近更新 更多