Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 6 years ago

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

Log in to vote
1
Answered by 6 years ago

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.

0
Thanks, it fixed it. You guys are very helpful here. :) Superameno 34 — 6y
Ad

Answer this question