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.
How do you make a GUI appear upon mouseclick? (And disappear.)
3 answers
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)
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
click the near where u spawn
the part ^
you can just do Sg.Enabled = not Sg.Enabled
That didn't seem to work.
i updated it try again
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.
it doesnt have to be enabled
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?
OH
Dont use a local script
https://gyazo.com/4be3d52828c62656190d1a497eab0e3b The script itself. https://gyazo.com/fe57d189e76676e41a32b2dc800191ce What I put the script inside of.
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
the gui is triggered upon clickdetection.
oh
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Did u get it?