im making settings for my game, one of the settings is showing/ not showing seats across the map. the text changes accordingly to the script but the seats transparency doesnt change at all
how do i get this to work?
the script of the gui button:
local button = script.Parent
local originalText = "Shown"
local seats = workspace.SeatsFolder:GetChildren()
button.MouseButton1Click:Connect(function()
if button.Text == originalText then
button.Text = "Hidden"
for i = 1, #seats do
if seats[i]:IsA("Seat") then
seats[i].Transparency = 1
end
end
else
button.Text = originalText
for i = 1, #seats do
if seats[i]:IsA("Seat") then
seats[i].Transparency = 0
end
end
end
end)
Seemed to work for me… Are you using Seat objects, or are the they just called Seat. IsA(“Seat”) would be looking for Seat objects rather than something named Seat
Have you tried debugging by the use of printing through the console to figure out where the script goes wrong? This can then help you to figure out what could possibly be causing the issue for you.
Its a loading issue, the seats folder is returning an empty array because no children actually exist when it goes to get them, Try using this
local seatsFolder = workspace:WaitForChild("SeatsFolder") -- Wait for folder to load
local Oneseats = seatsFolder:WaitForChild("Seat") -- Wait for children to load
local seats = seatsFolder:GetChildren()
Here is also the same script before with debugging print statments
local button = script.Parent
local originalText = "Shown"
local originalText = "Shown"
local seats = workspace.SeatsFolder:GetChildren()
print(seats)
button.MouseButton1Click:Connect(function()
if button.Text == originalText then
print("Passed, changing seats to transparent")
button.Text = "Hidden"
for i = 1, #seats do
print("Run: " .. i)
if seats[i]:IsA("Seat") then
print("Is a seat!")
seats[i].Transparency = 1
end
end
else
print("Failed to pass, changing seats to be visible")
button.Text = originalText
for i = 1, #seats do
print("Run: " .. i)
if seats[i]:IsA("Seat") then
print("Is a seat!")
seats[i].Transparency = 0
end
end
end
end)
Though actually depending on the lag, this is probably a better approach:
local seatsFolder = workspace:WaitForChild("SeatsFolder")
repeat
task.wait()
until #seatsFolder:GetChildren() > 0 -- Change this to a number closer to actualy how many seats you have
local seats = seatsFolder:GetChildren()