Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I make this part with a click detector open enable a Screen Gui?

This is my current code

local clickDetector = script.Parent.ClickDetector

local function openMenu(player)
	game.StarterGui.WelcomeGui.Enabled = true
end

clickDetector.MouseClick:Connect(openMenu)

I am trying to make it so when that part is clicked, it will enable a ScreenGui that I have disabled in StarterGui. I have tried it but nothing shows in Dev Console so I don't know what's wrong.

1 answer

✓ Accepted answer

###This is because the WelcomeGui is not in StarterGui. It is in PlayerGui. Seeing your script is a server script, the contents of PlayerGui cannot be accessed by the server unless the server placed it there. However, you shouldn't be doing anything GUI related on the server. Instead, use a RemoteEvent.

-- LocalScript, under your WelcomeGui

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local WelcomeEvent = ReplicatedStorage:WaitForChild("WelcomeEvent")

WelcomeEvent.OnClientEvent:Connect(function()
    script.Parent.Enabled = true
end)

###Server script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local WelcomeEvent = ReplicatedStorage:WaitForChild("WelcomeEvent")
local clickDetector = script.Parent.ClickDetector

local function openMenu(player)
    WelcomeEvent:FireClient(player)
end

clickDetector.MouseClick:Connect(openMenu)

###Read on common mistakes here.

1 comment

0

Thanks, it fixed it. You guys are very helpful here. :)

This discussion is preserved as it was. New answers, comments, and votes are closed.