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

How to use Click Detector to open a Gui?

Asked by 5 years ago
Edited 5 years ago

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

Log in to vote
0
Answered by
HaveASip 494 Moderation Voter
5 years ago
Edited 5 years ago

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)
0
char isn't the character Spjureeedd 385 — 5y
0
Sorry, I fixed that. Now it should be work HaveASip 494 — 5y
Ad
Log in to vote
1
Answered by
0RKH 35
5 years ago
Edited 5 years ago

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.

0
But I don't know who will play the game. So I don't know the names Spjureeedd 385 — 5y
0
Like I said, it will check who clicked it so you don’t have to worry. 0RKH 35 — 5y
0
But in the if player.name == "Here I need a name" Spjureeedd 385 — 5y
0
Yeah what person do you want in there?What name? 0RKH 35 — 5y
View all comments (6 more)
0
Anyone will be able to play it. I don't know the name on everyone who will play my game Spjureeedd 385 — 5y
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. 0RKH 35 — 5y
0
Yeah i understand that, but i want anoyone to be able to click it Spjureeedd 385 — 5y
0
Then you don’t need the if statement, PS: just remove the second line. 0RKH 35 — 5y
0
I've already tried that, doesn't work Spjureeedd 385 — 5y
0
Check for errors. 0RKH 35 — 5y
Log in to vote
-1
Answered by 5 years ago

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)
0
You cant access player's playergui stuff from server script if filtering is enabled, so you need to use remote events for that HaveASip 494 — 5y
0
But how do I get the character? Spjureeedd 385 — 5y
0
Sorry, should have told you it's a local script. Wait I'll update Spjureeedd 385 — 5y
0
MouseClick passes the player, not the player's character green271 635 — 5y
0
Then why GetPlayerFromCharacter? Spjureeedd 385 — 5y

Answer this question