2010-12-15 5 views
-3

Comment est-ce que je fais qu'un manuscrit fasse apparaître une interface graphique de magasin quand une brique est touchée?J'ai besoin d'un script qui amène un Gui au toucher dans Roblox?

Et comment devrais-je faire les choses "acheter" dans l'interface graphique de la boutique?

+3

Nous ne sommes pas ici pour écrire votre code pour vous. Peut-être que si vous réduisiez la question à un domaine spécifique avec lequel vous avez des problèmes, quelqu'un serait en mesure de trouver une solution. –

Répondre

2

Créez un script qui connecte l'événement «Touched» d'une brique à une fonction qui utilise la méthode «getPlayerFromCharacter» du jeu. Les joueurs trouveront ensuite le lecteur dans le «PlayerGui» du lecteur. Par exemple:

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

Vous serez besoin de faire cette boutique Interface vous, mais je vais vous donner le script « GUI Donateur ».
Note: Vous devez mettre le script à l'intérieur la brique/pièce.

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

Le code suivant peut être utilisé pour donner au joueur la boutique IUG:

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) 

Notez que « ShopPart » devrait être une grande partie qui couvre toute la zone du magasin (de préférence invisible)

Ensuite, vous devez également créer une boutique gui.

Dans la boutique vous devez faire IUG TextButtons (ou des boutons d'image) que chaque contient le script suivant:

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) 

Le code n'a pas été testé, il peut contenir des erreurs. Et vous pourriez avoir besoin de changer plus de choses que mentionné. Mais il devrait vous donner une idée sur la façon de rendre le shop gui =)

Questions connexes