Reputation: 33
Summarize the problem I've been trying to give the Table name to a variable. Everytime someone clicks a table a part with the table name get sent in TakeToTable. I get the part name and then go search for that table in the workspace to do somethings.
SearchTable gives me the right output.
Table gives me nil and it's strange cause the name is correct and the part exist in the workspace.
Describe what you’ve tried I've tried writing it in different ways, but I can't come out with anything.
When appropriate, show some code
while index == 0 do
i += 1
SearchTable = ClickDetect.TakeToTable:FindFirstChild("Table"..i)
if SearchTable ~= nil then
index = 1
end
end
print(SearchTable)
local Table = game.Workspace.Tables:FindFirstChild(SearchTable)
print (Table)
Example If the table it's the "Table12", The SearchTable will give me that exact output, but the variable Table will give me a nil, meaning it hasn't found it, When the table it's there.
Upvotes: -1
Views: 186
Reputation: 505
In the while loop, SearchTable
is set to the instance - however, you need the name. Simply take the name of it when you call FindFirstChild
.
while index == 0 do
i += 1
SearchTable = ClickDetect.TakeToTable:FindFirstChild("Table"..i)
if SearchTable ~= nil then
index = 1
end
end
print(SearchTable)
local Table = game.Workspace.Tables:FindFirstChild(SearchTable.Name) --change here
print (Table)
Upvotes: 1