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

How to open a GUI from brick?

Asked by 5 years ago
Edited 5 years ago

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

Log in to vote
0
Answered by 5 years ago

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.

0
you dont really need to use a serverscript or remote event for this purpose, the client can listen to touched events theking48989987 2147 — 5y
0
you dont really need to use a serverscript or remote event for this purpose, the client can listen to touched events theking48989987 2147 — 5y
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 alphawolvess 1784 — 5y
0
how do you really use remote events CaptainGalexyCreeper 15 — 5y
Ad
Log in to vote
0
Answered by
nachsor 36
5 years ago

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

Answer this question