Hello. I have a ClickDetector inside of a rig that activates a frame inside of a chatbox ScreenGui. Not sure how to make it work, I’ve tried both enabling the ScreenGui itself and the Frame.
local ClickDetector = script.Parent
local Player = game:GetService("Players")
local ChatBox1 = game.StarterGui.ChatBox1
local function clickFunction()
local frame = ChatBox1.Frame
if frame.Visible == false then
frame.Visible = true
end
end
ClickDetector.MouseClick:Connect(clickFunction)
Don’t use gui in starter gui, rather get them from PlayerGui. This is because StarterGui is just a container from which gui is cloned from; the PlayerGui is the one which receives these clones and renders them onto the player’s screen.
local LocalPlayer = Player.LocalPlayer
local ChatBox1 = LocalPlayer.PlayerGui:WaitForChild("ChatBox1")
That’s because on runtime, all instances in StarterGui are transferred into PlayerGui. Meaning that your ChatBox1’s variable pathing is incorrect here!
The correct path here would be:
local LocalPlayer = Players.LocalPlayer
local ChatBox1 = LocalPlayer.PlayerGui:WaitForChild("ChatBox1")
Nevermind. Seems like it doesn’t work still. I’m sure your answers are fine but is there a different way to make the ClickDetector activate the script inside the function? Or should I resort to enabling the ScreenGui instead of the Frame? Here’s how my code looks now.
local ClickDetector = script.Parent
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local ChatBox1 = LocalPlayer.PlayerGui:WaitForChild("ChatBox1")
ClickDetector.MouseClick:Connect(function()
local frame = ChatBox1.Frame
if frame.Visible == false then
frame.Visible = true
end
end)