Hello, i need help with displaying ScreenGui on player’s screen when he clicks on another player. So i have a textlabel and it should display clicked player’s name and some other stuff about player
so i just need to know how to Enable PlayerInfo gui on player’s screen (not the clicked player) and then get clicked player’s character (like game.Players:GetPlayerFromCharacter(click.Parent) but it doesnt work)
here’s the code that i tried:
local Player = game.Players.LocalPlayer
local Gui = Player.PlayerGui:WaitForChild("PlayerInfo")
local ClickDetector
for i, part in pairs(game.Workspace:GetDescendants()) do
if part:IsA("ClickDetector") and part.Name == "ProfileClick" then
ClickDetector = part
end
end
ClickDetector.MouseClick:Connect(function(click)
Gui.Frame.pName.Text = click.Parent.Name
Gui.Enabled = true
end)
1 Like
Have you tried debugging your code? Is your issue that nothing happens in the MouseClick event, or you are having trouble getting the player’s info?
Provide more details on your issue please.
By the way you should consider using CollectionService instead of that loop at the start of the script, like this:
local CollectionService = game:GetService("CollectionService")
local Player = game.Players.LocalPlayer
local Gui = Player.PlayerGui:WaitForChild("PlayerInfo")
local ClickDetectors = CollectionService:GetTagged("ClickDetectorTag")
for i, clickDetector in pairs(ClickDetectors) do
clickDetector.MouseClick:Connect(function(click)
Gui.Frame.pName.Text = click.Parent.Name
Gui.Enabled = true
end)
end
You just need to add the “ClickDetectorTag” to the ClickDetector instance:
As for your issue, provide more info and then I’ll be glad to help you Maybe add print()
functions in your code to see what runs correctly and what doesnt
1 Like
hey, your script worked fine, but after another player loads in game you can’t see his “profile” (unable to click gui) but click detector exists. though that player can click on you and see your profile
I’m confused. What do you mean by that? Also, how are you adding the click detector to the player’s character? Do you have a script for that?
basically this gui that i created is “profilegui” and when i mean that i click on him to see his “profile” is that i’m waiting for my gui to display on screen with clicked players name. and clickdetector is added by “StarterPlayer” so when player loads in game they load with ProfileClick clickdetector. i checked and both players have the Clickdetector so they can be interacted, but when 2nd player joins the game it just doesnt display gui on him anymore
Because your code utilizes CollectionService and specally, “GetTagged” it only returns the CURRENT tags that are saved in that table. Your fix is simple, add an event that detects when a player joins/leaves OR GetInstanceAddedSignal. Please review the CollectionService documentation here.
Example:
Player1 Joins @ 7:15PM
Current players: John, UncleTimmy
When your code runs for Player1, it will “GetTagged;” therefore, you will get the tags of said current players and create an array. BUT, because your GetTagged array doesn’t update, John & UncleTimmy will not see Player1s Tag.
Does this make sense?
1 Like
I haven’t thought about that, thank you for the explanation and clarification! I’m curious to see if it works for them
1 Like