Hello everyone! I have a big question. How do I refer to a far away part?
Lets say I have a part in the workspace with a click detector in it. Then I also have a screen gui with a text label inside of the starter gui. Now when I click the click doctor it will make the text label visible. But I don’t know how to refer to it that far.
if game.Worspace.Part:FindFirstChild("Click Detector").MouseClick:Connect(function()
script.Parent.TextLabel.Visible = true
end)
heres the issue I believe. Im using the term FindFirstChild wrong I think. Is there a way to make this work?
Hello!
I would like to understand what do you mean with a “far away part”? Are you talking about a part that is physically far away from the player?
There are several issues with your code, I will write them down here.
Unless you manually named the ClickDetector, “Click Detector” will not be a child of your part.
I assume this is a LocalScript. Otherwise, you are trying to modify a GUI object using a Server script, which is a bad practice.
You are first looking for the child named Click Detector using a conditional statement. By immediately after connecting a function to its “MouseClick” event, it becomes useless. You should first make sure the Child of the given name exists, and, if and only if it does, connect the function!
Well, the server does not even need access to a player’s Gui. You can use a LocalScript inside the Part if you want, and every time a player clicks the part, their gui comes up.
local ClickDetector = workspace.Part:WaitForChild("ClickDetector")
ClickDetector.MouseClick:Connect(function()
script.Parent.TextLabel.Visible = true
end)
Also a slight explanation, but the reason why a Server Script won’t work is because the changes are actually being made across the server-side, and not the client side (Or what you see on your screen) If you change it to a LocalScript, you should be all set