I have a script that when hovering over a part, shows the name of the part.
I then made it so a ClickDetector gets inserted into the part my mouse is hovering over.
I want to make it so that when clicking that part, a TextLabel’s value shows the part name, yet I’m struggling to do that since I can’t find the specific ClickDetector since the part I select is given a random name.
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local values = plr.PlayerGui.Input.TextBox
local click = Instance.new("ClickDetector")
local c
mouse.Move:Connect(function()
local target = mouse.Target
for _,blocks in pairs(workspace.Blocks:GetChildren()) do
if target == blocks then
if not(blocks:FindFirstChild("ClickDetector")) then
c = click:Clone()
c.Parent = target
values.id.TextTransparency = 0
values.PartName.Text = target.Name
end
else
if blocks:FindFirstChild("ClickDetector") then
c:Destroy()
values.id.TextTransparency = 1
values.PartName.Text = ""
end
end
end
end)
workspace.Blocks.Part.ClickDetector.MouseClick:Connect(function()
values.idSelected.Text = values.PartName
end)
(the parts the ClickDetectors get put in are given random names using HttpService, so the target is used to find the part regardless of the name, yet due to this, if I have multiple parts, I need it to find the ClickDetector in the part regardless of the name)
Here’s how I would do it. Insert a script inside your click detector that transfers it’s name to a int value or a strong value, id recommend using remotes to send to the int value or string value, then just grab tje value of that and put it on a text label
This is an example of the randomized name I forgot to mention.
It has a random 7 character string for every part cloned and put in that folder, and when hovered over, it puts a ClickDetector in that respective part.
while wait() do
game.ReplicatedStorage.RemoteEvent:FireServer(function(script.Parent.Name)
remoteevent.OnServerEvent:Connect(script.parent.Name)
label.text = script.parent.name