I need a Script that brings up a Gui on touch in Roblox?
How do I make a script bring up a shop GUI when a brick is touched?
And how should I make the "buy" stuff i开发者_运维技巧n the shop GUI?
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)
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)
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 =)
精彩评论