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

How do you make a GUI appear upon mouseclick? (And disappear.)

To give you a better idea, I want the player to spawn in with the GUI not being on their screen. If it's invisible, they might still accidentally click it even though it's invisible. Is there anyway to completely remove the GUI when they haven't clicked on the player, but when they click on the player, it appears? One more thing is how would I go about deleting it if they press the close button on the GUI, I imagine I would use the destroy function.

1 comment

0

Did u get it?

3 answers

✓ Accepted answer

You can use the Destroy() function on almost any Instance, but the easiest way to achieve what your want is to use the Enabled property. An example of what you're looking for:

local plr = game:GetService'Players'.LocalPlayer
local mouse = plr:GetMouse()

mouse.Button1Down:Connect(function()
	pcall(function() --if the mouse is pointing in the air it wont print an error
		local target = mouse.Target --what object the mouse is pointing at
		if game:GetService'Players':GetPlayerFromCharacter(target.Parent) then --Checks if its a part of character
			script.Parent.Parent.Parent.Enabled = true --enables gui again
			script.Parent.Text = game:GetService'Players':GetPlayerFromCharacter(target.Parent).Name
		end
	end)
end)

script.Parent.Parent:WaitForChild'Close'.MouseButton1Click:Connect(function()
	script.Parent.Parent.Parent.Enabled = false --makes the gui temporarily disapear 
end)

where the script is located

Also if this doesn't work add a wait() at the beggining

Hope this helps!

-ThisIsAnAccount255

https://www.roblox.com/games/1613996984/The-Pr0fessors-Place

script.Parent.ClickDetector.MouseClick:connect(function(player)
	Sg = player.PlayerGui:WaitForChild("ScreenGui") --Gui name
	if Sg.Enabled == false then
	   Sg.Enabled = true
	elseif Sg.Enabled == true then
	    Sg.Enabled = false
	end
end)


13 comments

0

click the near where u spawn

0

the part ^

0

you can just do Sg.Enabled = not Sg.Enabled

0

That didn't seem to work.

0

i updated it try again

0

Should the GUI be enabled in the first place? Because I tried enabled and disabled to start and it didn't work. When I click on the part with the clickdetector nothing happens. The GUI doesn't enable or appear.

0

it doesnt have to be enabled

0

Yeah, I have it disabled. When I load into game and click it, I don't get an error, it just doesn't work. I used this script as a localscript inside of the clickdetector. Should I have been using just a script?

0

OH

0

Dont use a local script

0

put it in the part not the click detector

try this but keep the gui visible the entire time

local guiorigonalPos = Instance.new("Value", script) --script is the parent
guiorigonalPos.Name = tostring(gui.Position)
gui.Position = UDim2.new(2,0,0,0)
-- when you bring the gui in 
gui:TweenPosition(UDim2.new(tonumber(guiorigonalPos.Name)),"In","Linear",3,false) 
wait(3)
-- some things will need to be changed like the UDim2.new() and the 3

2 comments

0

the gui is triggered upon clickdetection.

0

oh

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