Good suggestions, unfortunately neither of them seemed to do anything.
Here’s the other script. It just references the folder in the table. The rest is just a function for when the player steps on the button.
local ServerScriptService = game:GetService("ServerScriptService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local levelUpEvent = ReplicatedStorage.LevelUp
local buildScript = require(ServerScriptService.BuildScripts.BuildScript)
local banks = workspace.Banks:GetChildren()
for _, bank in banks do
local owner = bank.Owner
local ceiling = bank.SecondFloor.Ceiling
local roofAccessFolder = bank.RoofAccess
local ATMFolder = bank.ATMs
local facadeFolder = bank.Facade
local lightsFolder = bank.Lights
local breakRoom = bank.BreakRoom
local buttons = {ATMFolder.ATM1.Button, ATMFolder.ATM2.Button, ATMFolder.ATM3.Button, ATMFolder.ATM4.Button,
ceiling.Ceiling1.Button, ceiling.Ceiling2.Button, ceiling.Ceiling3.Button, ceiling.Ceiling4.Button, ceiling.Ceiling5.Button,
roofAccessFolder.DoorWall.Button, roofAccessFolder.Floor.Button, roofAccessFolder.Wall1.Button, roofAccessFolder.Wall2.Button,
breakRoom.Door.Button, roofAccessFolder.Wall3.Button, roofAccessFolder.Stairs.Button, roofAccessFolder.Door.Button,
breakRoom.Lockers.Button, breakRoom.Storage.Button, breakRoom.BreakRoomStuff.Button, breakRoom.VendingMachines.Button,
facadeFolder.Pillars.Pillar1.Button, facadeFolder.Pillars.Pillar2.Button, facadeFolder.Pillars.Pillar3.Button,
facadeFolder.Pillars.Pillar4.Button, facadeFolder.Pillars.Pillar5.Button, facadeFolder.Pillars.Pillar6.Button,
facadeFolder.Pillars.Pillar7.Button, facadeFolder.Pillars.Pillar8.Button, facadeFolder.Front.Button,
lightsFolder.Chandelier.Button
}
for index, button in buttons do
local COST = button.Cost.Value
button.Touched:Connect(function(hit)
if not button:GetAttribute("Touched") then
button:SetAttribute("Touched", true)
if buildScript.instanceTouched(COST, hit, owner.Value, button.Parent, bank) then
button:Destroy()
local character = Players:GetPlayerFromCharacter(hit.Parent)
--Activate the next button if there is one
if #buttons > index then
buildScript.activateButton(buttons[index+1])
else
character.leaderstats.Money.Value += 3000
print("Bank Level 5 Completed. Awarded $3000")
levelUpEvent:Fire(bank, 8)
end
end
wait(0.1)
button:SetAttribute("Touched", false)
end
end)
end
end
It connects to this other part in the main module script. Which then takes it, runs it through a function to make sure the player has enough money to buy it, then runs it through the BuildInstance function.
function BuildScript.instanceTouched(COST, partTouched, ownerName, instance, bank)
if CheckPrice(COST, partTouched, ownerName, instance) then
BuildInstance(instance, bank)
return true
end
return false
end