So basically I'm trying to make it so whenever you click something using a ClickDetector
the TextLabels
inside my LabelGui
go invisible. Thing is, nothing happens, and the Output doesn't show any errors.
I have it all set out properly, and I've debugged the Script
, yet it doesn't work. The printing in the debugging works but the line that is supposed to make the TextLabels
invisible isn't.
Any help would be appreciated!
local remote = game:GetService("ReplicatedStorage").Events.ClickEvent script.Parent.ClickDetector.MouseClick:Connect(function() for i,player in pairs(game.Players:GetPlayers()) do remote:FireClient(player, "eventClick") end end) -- I don't need to debug this since it works in firing the `LocalScript`, meaning it works perfectly.
PlayerGui.Clicks.Click
(Clicks is a Folder, Click is the LocalScript)local remote = game:GetService("ReplicatedStorage").Events.ClickEvent local getchildren = script.Parent.Parent:WaitForChild("LabelGui") remote.OnClientEvent:Connect(function(eventClick) if eventClick == "eventClick" then getchildren:GetChildren().Visible = false print("yolo") -- Debugging to see if it works end end)
If you'd like to see more information and where I've placed my Events
and Scripts, LocalScripts, etc
then let me know and I'll post it in the Comments. I haven't posted it in this because I don't think it is the issue.
Thanks!
local remote = game:GetService("ReplicatedStorage").Events.ClickEvent local getchildren = script.Parent.Parent:WaitForChild("LabelGui") remote.OnClientEvent:Connect(function(eventClick) if eventClick == "eventClick" then getchildren:GetChildren().Visible = false print("yolo") -- Debugging to see if it works end end)
Did you think that this code was going to set the Visible
property of LabelGui
's children to false
? You thought wrong. The :GetChildren()
method returns an array, arrays are mappings from 1...#array to arbitrary values, and you can get an element from the array with a numerical key, say 2 (array[2]
), and you are trying to set Visible
, a string key. You can iterate over that array with a generic for loop.
for _, child in ipairs(getchildren:GetChildren()) do -- # `child` is the current child you are working with if child.Name == "name here" then child.Visible = false elseif child.Name == "other name" then child.Visible = true end end
Additionally, instead of calling :FireClient()
individually for each player you can just call :FireAllClients()
.
:GetChildren()
returns a table, and you're trying to set the Visible
property (which obviously doesn't exist in tables) to false. What you need to do is loop through the children. Also, it worries me that this did not give you an error, because it should have. Are you sure the server script is running?
local remote = game:GetService("ReplicatedStorage").Events.ClickEvent local Gui = script.Parent.Parent:WaitForChild("LabelGui") remote.OnClientEvent:Connect(function(eventClick) if eventClick == "eventClick" then for _,v in pairs(Gui:GetChildren()) do v.Visible = false end end end)