Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

how to check if a property is there?

Asked by
u_jew 0
7 years ago

I need to check if Text is a value, like

1for i,v in pairs(game.Players:GetDescendants()) do
2    if v.Text then
3        print("text property is here!")
4    end
5end

but actually works.

2 answers

Log in to vote
1
Answered by 7 years ago
1local foundText = false
2for i,v in pairs(game.Players:GetDescendants()) do
3   if v.Text ~= nil or v.Text ~= "" then
4    foundText = true
5    print("Text property has a value of: "..v.Text)
6   end
7end
Ad
Log in to vote
0
Answered by
mattscy 3725 Moderation Voter Community Moderator
7 years ago

If you only needed it for the Text property specifically, you could check if the instance was something that has a Text property (TextLabel,TextBox,TextButton) before referring to the property:

1for i,v in pairs(game.Players:GetDescendants()) do
2    if v:IsA("TextLabel") or v:IsA("TextBox") or v:IsA("TextButton") then
3        print("text property is here!")
4    end
5end

However, if you are using this to try and alter GUIs through a server script, it will not work. Instead, you might need to use FireAllClients() with a RemoteEvent, and check if it has the Text property in a LocalScript.

Answer this question