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)
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)
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.
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)