I recommend you studying the code I added so you can understand how you can access guis in a player. I added comments all over the scripts to make you understand a little better. ^^
I'm not quite sure about what you want to do with the "MainmenuGui", but here is a way to access it:
In the part that are going to be touched add:
script.Parent.Touched:connect(function(hit)
script.Disabled = true
if hit.Parent:FindFirstChild("Humanoid") then
print("It is a humanoid!")
local player = game.Players:WaitForChild(hit.Parent.Name)
player.PlayerGui.ThisWorks.Disabled = false
end
wait(1)
script.Disabled = false
end)
^^^^^^^^^^^^^^^^^^^^^^^^^^
So this is a server script which is inside the brick. It activates a localscript inside the player.
But hey! We gotta make a localscript too!
There are two ways in doing this:
1 - Making a serverscript which moves the script into the player (Will be able to change name of the script)
2 - Just adding a localscript into the PlayerGui (Can't change name of the script)
Option 1:
game.Players.PlayerAdded:Connect(function(plr)
local Storage = game:GetService("ServerStorage")
local ThisWorks = Storage:WaitForChild("ThisWorks")
ThisWorks.Parent = plr.PlayerGui
print("Finished")
end)
This is how my workspace looks like:
https://gyazo.com/4a29dda5e09982919fe8b039ae36fc62
I have now moved my localscript into the player, and the script will be enabled whenever I touch the part.
The last part you have to do is to put something into the localscript.
I just added some random stuff:
local player = game.Players.LocalPlayer
print("It works? How nice!")
script.Disabled = true
I hope you understand what I'm trying to show you. xD
I know this is kinda messy but I'm sure you'll figure it out.
You can now add:
local gui = player:WaitForChild("PlayerGui")
local mainMenu = gui:WaitForChild("MainmenuGui")
And there you have it. You got access to your MainmenuGui.
You can now do whatever you want with it.
I hope you find this helping. ^^
Enjoy!
~WaterFoox
2 comments
Infinite yield possible on a WaitForChild yield function typically means that the Gui doesn't exist. It might not be replicated to the client. Could I have more information on this? For example, where is this "MainmenuGui"?
In StartGUI, and I even copied the name from the gui into the script. But that didn't work