local Activate = script.Parent script.Parent.Touched:Connect(function(hit) then ScreenGui.Enabled = true end
You dont need to enable/disable screengui.You can make the childs of it visible/invisible.
If you don't mind make sure to put parts and objects into game.workspace also here is a simple script
local part = game.workspace.part -- put part name here make sure it is a Part not model part.Touched:Connect(function() ScreenGui.Enabled = true end)
if this doesn't work then tell me the error you get!
Considering your code provided, there are multiple issues.
script.Parent.Touched:Connect(function(hit) then
, I don’t see why you have a then here when this isn’t an if statement.
ScreenGui
is not defined.
You’re firing .Touched
for every object that touches it, meaning your studio could crash due to every object in your game touching it
Since I assume this is a local script (you should always use them for UI manipulation), they won’t work in the workspace, it’s best that you use a Script to detect .Touched and a remote event to a Local Script to turn on your GUI
Hope this answers your question
Guis are typically LocalScripts because they immediately replicate (if using StarterGui) to the LocalPlayer.PlayerGui
. BasePart.Touched
is an event that is typically used on Server Scripts. If you want to make the Gui visible, then use a Remote Event which fires to the client.
--//Server Script\\-- local part = script.Parent --I'm assuming the child of the part is the script part.Touched:Connect(function(hit) if game.Players:GetPlayerFromCharacter(hit.Parent) then --Use this to find a player. game.ReplicatedStorage.RemoteEvent:FireClient(game.Players:GetPlayerFromCharacter(hit.Parent)) end end)
So I just immediately fired a client to the player. Now I need to get it.
--//Local Script\\-- local remoteEvent = game.ReplicatedStorage.RemoteEvent remoteEvent.OnClientEvent:Connect(function() script.Parent.TextLabel.Visible = not script.Parent.TextLabel.Visible --if true then false and vice versa end)
This is the basic way to get a Pop-up Gui. You can experiment more and even improve on the script I have, but this is the most basic method. (Note: This does not account for debounce or anything like that, it's just a basic script.) Sources: AlvinBlox OpenGuiWithPart Remote Events and Functions OnClientEvent