The title already explains it all. This is my script. I’ve been trying to fix this for almost 7 and a half hours now, so if you know how to fix it, please do! Thanks.
Script Context
This is for a tycoon and the “Unlocks” is a folder for everything a button unlocks.
This script is in server script service so it uses tags to get all buttons
ChildrenOfBought technically ChildOfBought but I didn’t feel like chaning it
ChildOfBought is basically everything inside of Unlocks.
Before the game starts, it turns all the unbought stuff invisible.
Script
function PressurePlateButtons(v)
if v.Name ~= "StartButton" then
v.Transparency = 1
end
local pressurePlate = v
local base = pressurePlate:FindFirstAncestor("BASE")
local droppers = {}
local transparencies = {}
local function fadeTween(part, goal, Time)
ts:Create(part, TweenInfo.new(Time, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), goal):Play()
end
-----------------------THIS IS THE WHILE LOOP THE PROBLEM IS HAPPENING IN!!!
local function vis(parent, turnInVis, Time, onlyInUnlocks, invLabel)
for i, childrenOfBought in pairs(parent:GetChildren()) do
wait()
print(childrenOfBought)
if childrenOfBought.Name ~= "Unlocks" and not transparencies[childrenOfBought.Name] then
print("Went", childrenOfBought)
if turnInVis == 1 then--invisible
local s, f = pcall(function()
repeat wait() print("waiting", childrenOfBought, childrenOfBought.Transparency, childrenOfBought.Parent.Parent) transparencies[childrenOfBought.Name] = {childrenOfBought.Transparency} until transparencies[childrenOfBought.Name][1] ~= 1
print("Donee", childrenOfBought)
coroutine.wrap(fadeTween)(childrenOfBought, {Transparency = turnInVis}, Time)
end)
print(f, childrenOfBought)
local s, f = pcall(function()--TextLabels don't have CanCollide so if I put this in the other pcall, it would break the whole function for the TextLabel
transparencies[childrenOfBought.Name][2] = childrenOfBought.CanCollide
childrenOfBought.CanCollide = false
end)
print(f, childrenOfBought)
else--visible
print("visible", childrenOfBought)
local _, fail = pcall(function()
coroutine.wrap(fadeTween)(childrenOfBought, {TextTransparency = invLabel}, Time)
end)
print(childrenOfBought, fail)
if fail then
if transparencies[childrenOfBought.Name] then
print(childrenOfBought)
childrenOfBought.CanCollide = transparencies[childrenOfBought][2]
coroutine.wrap(fadeTween)(childrenOfBought, {Transparency = transparencies[childrenOfBought][1]}, Time)
print(transparencies[childrenOfBought], childrenOfBought.Transparency, childrenOfBought.CanCollide, childrenOfBought)
end
print(childrenOfBought)
end
warn(transparencies)
print(childrenOfBought, fail)
end
vis(childrenOfBought, turnInVis, Time, "Unlocks", invLabel)
end
end
end
--FindDroppers
for i, v in pairs(pressurePlate.Unlocks:GetChildren()) do
if (v.Name:lower():match(("Dropper"):lower())) and not v:HasTag("Button") then
table.insert(droppers, v)
end
end
--Invis all Unlocks
vis(pressurePlate.Unlocks, 1, 0, "GoThroughAllUnlocks", 0)
local touched = false
local c
c = pressurePlate.Touched:Connect(function(toucher)
if touched == true then return end
if not toucher.Parent:FindFirstChild("Humanoid") then return end
local char = toucher.Parent
local plr = game:GetService("Players"):GetPlayerFromCharacter(char)
if pressurePlate.Transparency == 1 then return end
if not plr then return end
touched = true
c:Disconnect()
pcall(function()pressurePlate.Head:Destroy() pressurePlate.BillboardGui.TextLabel.TextTransparency = 1 end)
fadeTween(pressurePlate, {Transparency = 1}, 1)
--fadeTween(pressurePlate.BillboardGui.TextLabel, {TextTransparency = 1}, 1)
vis(pressurePlate.Unlocks, 0, 1, "Unlocks", 0)
for i, dropper in pairs(droppers) do
local Type, IndexNum = MakeDropper.FindType(dropper)
local dropperTable = MakeDropper.NewDropper(dropper, Type, base, toucher.Parent)
if dropperTable then
dropperTable:Drop()
end
end
end)
end
for i, v in pairs(cs:GetTagged("Button")) do
--Script by BlueBLoxBlast(Ask me if something broke)
task.wait(.0)
PressurePlateButtons(v)
--very interesting
end
isGameReady = true
warn("LOADTIME LOADTIME LOADTIME LOADTIME LOADTIME", tick() - start)