ClickDetector inside model not enabling frame

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.

image
image

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)

Any help and tips are greatly appreciated.

1 Like

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")
2 Likes

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")
2 Likes

Ah. I see. Thank you for your explanations. Have a good day.

1 Like

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)
1 Like

Localscripts don’t run when parented to a model that isn’t a character. Move the script to StarterGui or StarterPlayerScripts

2 Likes

So it’s not fine if I have the script inside of a Rig? I’ll try your solution then.

1 Like

Okay. Putting the script into StarterGui worked. Thanks so much. Have a good day.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.