Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do i make a Touched event that will open a GUI ? [closed]

Asked by 5 years ago
So i need to do so peoples can buy stages on my simulator game but i cant figure out how to do a touched event that will open a frame that will say Buy stage ? yes or no ive been stuck on it for 2 days :/
0
Try and make your question a bit more constructive. sonysunny 36 — 5y
0
Please include code and fix the formatting: https://scriptinghelpers.org/help/how-post-good-questions-answers xPolarium 1388 — 5y
0
So basically i need so if u touch a part a Frame will pop up where its a text label that says "You dont own Stage 1!" and 2 buttons "Yes" and "No" but i cant make so if u touch the part that comes up :/ how do i do that TeoMessiKing -5 — 5y
0
You don't need to keep switching accounts, just saying. sonysunny 36 — 5y

Closed as Not Constructive by Ziffixture, CaptainD_veloper, and theking48989987

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?

3 answers

Log in to vote
0
Answered by
Clorize 31
5 years ago
Edited 5 years ago

I've found a working solution. So my method is to clone the GUI and put it in a player's PlayerGui. This script is very basic (Note: To have multiple frames show up, make sure they are in the ScreenGui you wish to clone.)

local gui = game:GetService("ReplicatedStorage"):WaitForChild("ShopGui")

script.Parent.Touched:Connect(function(hit)
    if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
        local clonedgui = gui:Clone()
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        clonedgui.Parent = player.PlayerGui
    end
end)
0
thank you TeoMessiKing -5 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

I will entertain your question because you are new.

For future reference, you must first try to make the script yourself, then if it doesn't work, come to us for help.

You will have to fill in a couple of things as you didn't give me a script to fix:

local PartThatIsTouched = workspace.PartNameHere
local PlayerGui = game.Players.PlayerGui

repeat 
    wait()
until 
    PlayerGui:FindFirstChildOfClass'ScreenGui'

local ScreenGui = PlayerGui:FindFirstChildOfClass'ScreenGui'

local GuiToPopUp = ScreenGui:WaitForChild(
    "Your gui name here" -- put your gui name here between the quotes
)

PartThatIsTouched.Touched:connect(function()
    GuiToPopUp.Visible = true
end)

GuiToPopUp:WaitForChild(
    "Your first button name here"
).MouseButton1Click:connect(function()
    -- your code here
end)

GuiToPopUp:WaitForChild(
    "Your second button name here"
).MouseButton1Click:connect(function()
    -- your code here
end)


0
Wow, the amount of lines of code in your response is way superior to mine. Clorize 31 — 5y
0
I will entertain your question because you're not very experienced in lua. You're teaching very bad habits. A repeat loop to wait for a object is an awful method, WaitForChild is there for a reason. You're also using FindFirstChildOfClass, when you should be using FindFirstChild. Your code is also extremely spread out and unreadable. NodeSupport 32 — 5y
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

As seen on the Wiki, onTouch can be called via both LocalScripts and normal Scripts.

In order to do what you're asking you should place a LocalScript inside of

StarterPlayer > StarterPlayerScripts

Inside of this localscript you should define your part that's located inside of the workspace. Please replace PARTNAME with your parts name.

local Part = game:GetService("Workspace"):WaitForChild("PARTNAME")
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local gui = game:GetService("ReplicatedStorage"):WaitForChild("ShopGui")

Part.Touched:connect(function(partTouched)
    if Players:GetPlayerFromCharacter(partTouched.Parent) and partTouched.Parent.Name == LocalPlayer.Name then
        if gui.Frame.Visible == false then
            gui.Frame.Visible = true
        end
    end
end)

Please mark this as your solution if it helped.