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

How to open a GUI from brick?

I've figured out how to use the "On Touch" function and now i'm trying to figure out how to open a gui from it. Here is the script i'm using.

function Touch(hit) if hit.Parent:FindFirstChild("Humanoid") then local GUI = game:GetService("StarterGui"):WaitForChild("Test") if GUI then GUI.Enabled = true end end end

script.Parent.Touched:Connect(Touch)

2 answers

✓ Accepted answer

There are few cases where you'll need to manipulate GUI's within StarterGui. The StarterGui's purpose is to replicate GUIs to the PlayerGui, which is where all the UI is stored that a user can see.

Your code has three main issues:

  1. You are attempting to edit a GUI within StarterGui, not PlayerGui

  2. You never find the Player who touched so you may access PlayerGui

  3. Assuming this is a Script, you cannot access PlayerGui without using a RemoteEvent or RemoteFunction


The below fixes are based on the above issues. You will need to add a RemoteEvent to ReplicatedStorage and name it "EnableGui" and add a localscript to PlayerGui inside of the GUI you are enabling.

-Script

local EnableGui = game.ReplicatedStorage:WaitForChild("EnableGui")
function Touch(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		EnableGui:FireClient(game.Players:GetPlayerFromCharacter(hit.Parent))
	end
end

script.Parent.Touched:Connect(Touch)

-localscript

local EnableGui = game.ReplicatedStorage:WaitForChild("EnableGui")

EnableGui.OnClientEvent:Connect(function()
	script.Parent.Enabled = true	
end)

If you have any issues or questions, then feel free to comment below.

4 comments

0

you dont really need to use a serverscript or remote event for this purpose, the client can listen to touched events

0

you dont really need to use a serverscript or remote event for this purpose, the client can listen to touched events

0

I'm aware, I figured I'd give an answer closely related to what the poster came up with. Also to introduce Remotes and their purpose. Feel free to give an alternative answer

0

how do you really use remote events

I don't know if this helps but try using this:

script.Parent.Touched:Connect(function(hit)

print("Debug Message")
local playername = hit.Parent.Name
local player = game.Players:WaitForChild(playername)
local playergui = player:WaitForChild("PlayerGui")
local GUI = playergui:FindFirstChild("Test")


if GUI then
	GUI.Enabled = true
end

end)

I did test it but you know Roblox studio, one thing might work for someone but not for another. Anyways I hope this helps! :D

P.S. I don't know why it didn't put the whole code block in but eh, works just the same

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