✓ 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:
You are attempting to edit a GUI within StarterGui, not PlayerGui
You never find the Player who touched so you may access PlayerGui
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
you dont really need to use a serverscript or remote event for this purpose, the client can listen to touched events
you dont really need to use a serverscript or remote event for this purpose, the client can listen to touched events
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
how do you really use remote events