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)
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.
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