Hey! Over the past day I’ve worked on some sort of bank system and would like some feedback on its efficiency and anything else that comes to mind.
Right now, this only checks if they’re in or out of the bank. I’m still working on giving cash and a timer but I’d like to get a review before committing fully.
The main bit is the function Robbery(part)
, you can ignore everything else if you wish to. Just wanted to include everything.
Full code:
local Players = game:GetService('Players')
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local Events = ReplicatedStorage.Events
local BankEvent = Events.BankEvent
local Settings = script.Settings
local Open = Settings.Open
local Robbing = Settings.Robbing
local Rob_Amount = Settings["Rob Amount"]
local Vault = Settings.Vault.Value
--local vaultPart = workspace.Map.Bank.Vault
local maxParts = 20
local ignore = {}
local PlayersTag = {}
local chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_+-={}|[]`~'
Players.PlayerAdded:Connect(function(plr)
local length = 12
local randomString = ''
local charTable = {}
for c in chars:gmatch"." do
table.insert(charTable, c)
end
for i = 1, length do
randomString = randomString .. charTable[math.random(1, #charTable)]
end
local boolValue = Instance.new('BoolValue', plr)
boolValue.Name = randomString
PlayersTag[plr] = {}
table.insert(PlayersTag[plr], {
string1 = boolValue
})
end)
function RobberyTime()
local OpenTime = math.random(5, 10)
wait(OpenTime)
print('Robbing may begin')
Open.Value = true
wait(.5)
Robbery(Vault)
end
Open.Changed:Connect(function()
if Open.Value == false then
RobberyTime()
end
end)
function CreateRegion3FromPart(Part)
return Region3.new(Part.Position - (Part.Size/2), Part.Position + (Part.Size/2))
end
function Robbery(part)
local Robbers = {}
while wait(.5) do
if Open.Value == true then
local region = CreateRegion3FromPart(part)
local partsInRegion = workspace:FindPartsInRegion3(region, nil, math.huge)
for _, Player in next, Players:GetPlayers() do
local check = false
for _, v in next, partsInRegion do
if Players:GetPlayerFromCharacter(v.Parent) then
check = true
local Character = Player.Character
if Character and Character.Humanoid.Health > 0 then
local myTag = PlayersTag[Player][1].string1
myTag.Value = true
table.insert(Robbers, Player)
print(Player.Name.." has begun robbing")
end
else
-- it's a part
end
end
wait()
if check == false then
local myTag = PlayersTag[Player][1].string1
myTag.Value = false
for i, plr in next, Robbers do
if plr == Player then
table.remove(Robbers, i)
print(Player.Name.. " has left the vault")
end
end
end
end
else
break
end
end
end
RobberyTime()
Thanks!