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

Why wont the gui appear when clickdetector is activated?

local frame = game.StarterGui.changeBodyColorGui.Frame

local function onClick()
	frame.Visible = true
end

script.Parent.MouseClick:Connect(onClick)

this is inside a click detector and i get no errors from the output, whats wrong?

3 comments

0

because you are changing startergui

0

wdym? I'm changing the frame

0

where is the script located

3 answers

✓ Accepted answer

Here's my code with an explanation.

script:FindFirstAncestorWhichIsA("ClickDetector").MouseClick:Connect(function(Player)
	--[[
	By using FindFirstAncestor you're looking through all the ancestors, aka 'Parent.Parent.Parent' but much shorter.
	If you noticed 'function(Player)', that's a built-in argument to the connection, use that to your advantage.
	Make sure this is a server-script & not a client-script. Make sure you're modifying it in the PlayerGui and not the StarterGui, the StarterGui is a service that allows you to modify the game GUIs much easier.
	]]
	Player:FindFirstChildWhichIsA("PlayerGui")["changeBodyColorGui"].Frame.Visible = true
end)

You're changing StarterGui, not PlayerGui

To change PlayerGui, just pass the player argument and reference PlayerGui from there

local function onClick(player)
    player.PlayerGui.changeBodyColorGui.Frame = true
end

script.Parent.MouseClick:Connect(onClick)

4 comments

0

oh, right thx, can't believe a forgot that

0

hold on, its not working

0

Any errors

0

no

Another thing is, you should not be using a click detector, for clicking a button, use a regular button, text button, image button OR don't use a local function.

script.Parent.MouseClick:Connect(function()
game.StarterGui.ScreenGui.Frame.Visible = false
end)

When dealing with frames, you always want a Click Detector to access the STARTERGUI because that's where everything is, if you're trying to get a certain item in someone's or on someone's screen that's where player gui comes in. You should probably use both but also don't forget that you should use a text button if it's a gui if it's not use a click detector.

3 comments

0

why are you editing startergui

0

Why would you edit player gui if you can do starter gui, when a text button is clicked you don't edit player gui do you?

0

You edit PlayerGUI - playergui is a container in which guis from the server are to be cloned to the player, hence the name "PlayerGui"! You can read more on the developer hub

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