Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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 :/

4 comments

0

Try and make your question a bit more constructive.

0

Please include code and fix the formatting: https://scriptinghelpers.org/help/how-post-good-questions-answers

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

0

You don't need to keep switching accounts, just saying.

3 answers

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)

1 comment

0

thank you

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)


2 comments

0

Wow, the amount of lines of code in your response is way superior to mine.

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.

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.