Hey developers, I am very new to scripting, and I want to be able to create a system listed below and be able to understand how it works.
What do you want to achieve? I want to be able to have a system where if a player has a certain GUI open, then clicks another player then the player that has just been clicked name appears on a GUI.
What is the issue? I can’t find any way to do this, I’ve searched youtube, google and the dev forums.
What solutions have you tried so far? I haven’t managed to try anything as I don’t know what is required to make this feature happen.
Here is my workspace if you need it.
The text label is part of the GUI is where the Players name will appear.
You can add a Script in StarterPlayer > StarterCharacterScripts with:
local clic_detector = instance.new("ClickDetector")
clic_detecor.Parent = script.Parent.Torso
– then when someone clicks the player, you need to add a function that will get the Player Name. You can search up Get Player name with clickdetector on the DevForum or google,
Get the mouse.Target and find the characters name. Then find the players name in the playerlist to confirm that it is an actual player and not a NPC.
local Mouse = game.Players.LocalPlayer:GetMouse()
function MB1()
local Target = Mouse.Target
local Checking = true
local HighestAncestor = Target
while Checking == true do
if HighestAncestor == game.Workspace then
Checking = false
break
else
HighestAncestor = HighestAncestor.Parent
end
if HighestAncestor:IsA("Model") then
local Players = game.Players:GetChildren()
if Players[HighestAncestor.Name] == nil then
-- It Could be a NPC
else
-- Create The Gui
end
end
end
end
Mouse.Button1Down:Connect(function(MB1()))
-- Disconnect this when the player leaves.
If this game is for PC then use the mouse.Target
If it needs more compatability then use Userinput service
You may have noticed I added in the start of npc detection in there, you can develop on that if you want to have NPC trade windows or interactions using GUIs
local clic = Instance.new("ClickDetector")
clic.Parent = script.Parent
function onClicked()
local name = clic.Parent
print(name.Name)
local char = script.Parent
local plr = game.Players:FindFirstChild(char.Name)
if plr then
print("found player")
local gui = plr:FindFirstChild("StaffMenu")
if gui then
print("found the ScreenGui")
local text = gui:FindFirstChild("Role_Assignment")
if text then
text.Frame.Input.Text = clic.Parent.Name
end
end
end
end
clic.MouseClick:Connect(onClicked)
And there’s nothing in the output, so there could be a problem really early on in the script, here is my explorer if you need it.