I wanted have a script when i touch the part in a folder it makes another part visible and this would serve as the base to a tycoon system. Currently, I loop through a folder and run a function to check if the part is touched and if it is it makes the transparency 0 and CanCollide true.
I want to see if I can give each of them an IntValue so even if the parts are in two separate folders I could “link” them with an IntValue so that when the specific part I touch has an IntValue of “1” and the part that I want visible has an IntValue of “1” it would match and only that part would be visible.
I’m also not sure if this causes lag since it would have to loop thru a large amount of parts however I’m open to hearing the feedback.
--scripted by sandy7512
local startTime = os.time()
local mainGame = game.Workspace:WaitForChild("scriptedparts")
local purchasePart = mainGame:WaitForChild("purchaseParts"):FindFirstChildWhichIsA("BasePart")
local partsChanged = mainGame:WaitForChild("partsChanged")
for _, v in partsChanged:GetChildren() do
if v:IsA("BasePart") then
v.BrickColor = BrickColor.new("Bright red")
v.Transparency = 1
v.CanCollide = false
end
end
local function checkChanged()
for _, v in partsChanged:GetChildren() do
if v:IsA("BasePart") then
v.BrickColor = BrickColor.new("Bright blue")
v.Transparency = 0
v.CanCollide = true
end
end
end
-- create a function that checks IntValues between purchasedParts and partsChanged
--debounce check
local partIsTouched = false
local function touchFunc(otherPart)
if not partIsTouched then
partIsTouched = true
if otherPart.Parent:FindFirstChild("Humanoid") then
checkChanged()
end
task.wait(2)
partIsTouched = false
end
end
purchasePart.Touched:Connect(touchFunc)
--load time check
print("PurchasePartServer loaded in", os.time() - startTime, "seconds")