2010-12-15 28 views
-3

レンガをタッチしたときにスクリプトを作成してショップGUIを表示するにはどうすればよいですか?RobloxでGuiを手に入れるためのスクリプトが必要ですか?

そして、私は店のGUIに「買い」のものをどうやって作っていいのですか?

+3

私たちはあなたのためのコードを書くためにここにいません。おそらく問題を特定の分野に絞り込んだ場合、誰かが解決策を指摘することができます。 –

答えて

2

レンガの「Touched」イベントをgame.PlayersのgetPlayerFromCharacterメソッドを使用してプレイヤーの「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) 
6

あなたはショップインターフェイス自分、 しかし、私はあなたに「GUI贈り主」スクリプトを与えることを確認する必要がされます。
注:スクリプトの中に入れなければなりません。

local Gui = game.Lighting.GUI --Replace this with the location of your GUI 

function GiveGui(Player) 
if Player.PlayerGui:FindFirstChild(Gui.Name)~=nil then return end 
Gui:Clone().Parent=Player.PlayerGui 
end 

script.Parent.Touched:connect(function(hit) 

local Player=game.Players:GetPlayerFromCharacter(hit.Parent) 
if Player==nil then return end 
GiveGui(Player) 

end) 
0

次のコードでは、プレイヤーにお店のGUI与えるために使用することができます:「ShopPartは」(望ましい見えない)全ショップエリアをカバーする大きな部分であることを

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) 

注意を

あなたはまた、店の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では、それぞれが次のスクリプトが含まれていることをTextButtons(または画像ボタン)を行う必要があります。そしてあなたは言及されているものより多くのものを交換する必要があるかもしれませんしかし、それはあなたに店を作る方法のアイデアを与えるべきであるgui =)

関連する問題