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

How to use Click Detector to open a Gui?

I have a problem! I want to click on a part and then I want a click detector to open a gui in the player's PlayerGui Folder. But I don't know how to find the right player! Please help me someone

This code is inside a LocalScript which is in a ClickDetector which is in a part

script.Parent.MouseClick:Connect(function(player)

	player.PlayerGui.ScreenGui.ImageLabel.Visible = true
end)

3 answers

✓ Accepted answer

For first insert RemoteEvent into replicatedstorage and replace the localscript inside the clickdetector to script and type in this

Other answers are bad

local Event = game:GetService("ReplicatedStorage"):WaitForChild("Example") --your RE name here
local CD = script.Parent

CD.MouseClick:Connect(function(Player)
	Event:FireClient(Player) --Firing to player
end)

Now insert a localscript inside the starterGui and type in

local Event = game:GetService("ReplicatedStorage"):WaitForChild("Example") --your RE name here
local Player = game.Players.LocalPlayer
local ImageLabel = Player.PlayerGui.ScreenGui.ImageLabel

Event.OnClientEvent:Connect(function() --this script starting work, when player clicked on the clickdetector
	ImageLabel.Visible = true 
end)

2 comments

0

char isn't the character

0

Sorry, I fixed that. Now it should be work

Maybe try this

script.Parent.MouseClick:Connect(function(player)
   if player.Name == "Name here” then
      game.Players.LocalPlayer.PlayerGui.ScreenGui.ImageLabel.Visible = true
   end
end)

This way, the if statement checks who clicked the click detector.If the person who clicked the click detector and his name was what’s in the "..." then it will continue to run the code.Hope this helps.

Also make sure the script is a local script.

10 comments

0

But I don't know who will play the game. So I don't know the names

0

Like I said, it will check who clicked it so you don’t have to worry.

0

But in the if player.name == "Here I need a name"

0

Yeah what person do you want in there?What name?

0

Anyone will be able to play it. I don't know the name on everyone who will play my game

0

Let me explain it, If player.Name == “badcc”, well if badcc is not in the server ANYONE that clicks it will not work.Only the person in the if player.Name == “...” will work.

0

Yeah i understand that, but i want anoyone to be able to click it

0

Then you don’t need the if statement, PS: just remove the second line.

0

I've already tried that, doesn't work

0

Check for errors.

You want to find the player connected to the character that is clicking the ClickDetector. You do that by typing GetPlayerFromCharacter()

Like this:

script.Parent.MouseClick:Connect(function(player)
	game:GetService("Players"):GetPlayerFromCharacter(player).PlayerGui.ScreenGui.ImageLabel.Visible = true
end)

5 comments

0

You cant access player's playergui stuff from server script if filtering is enabled, so you need to use remote events for that

0

But how do I get the character?

0

Sorry, should have told you it's a local script. Wait I'll update

0

MouseClick passes the player, not the player's character

0

Then why GetPlayerFromCharacter?

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