--// bolekinds


local Time = game:GetService("Lighting")
local Bandit = game.ServerStorage.Bandit
local BanditSpawns = workspace.BanditSpawns
local con
local mailboxcon

game.Lighting:GetPropertyChangedSignal("ClockTime"):Connect(function()
	if game.Lighting.ClockTime == 7 then
		local randomNum = math.random(1, 10)
		local banditRaid = false
		if randomNum >= 5 then
			banditRaid = true
		end
		game.ServerStorage.ServerData.Age.Value += 1
		game.ServerStorage.ServerData.Day.Value += 1
		if mailboxcon then
			mailboxcon:Disconnect()
		end
		if game.ServerStorage.ServerData.Day.Value >= 5 then
			if game.ServerStorage.ServerData.HasKeys.Value == false then
				workspace.Door.Knock:Play()
				workspace.Door.Sparkles.Enabled = true
				workspace.Door.ProximityPrompt.Enabled = true
				con = workspace.Door.ProximityPrompt.Triggered:Connect(function(plr)
					game.ServerStorage.key:Clone().Parent = plr.PlayerGui
					workspace.Door.Knock:Stop()
					workspace.Door.Sparkles.Enabled = false
					workspace.Door.ProximityPrompt.Enabled = false
					con:Disconnect()
				end)
			end
		end
		if game.ServerStorage.ServerData.HasKeys.Value == true then
			if banditRaid == true then
				workspace.Sound3:Play()
				game.ReplicatedStorage.Bandit:FireAllClients()
				repeat
					task.wait(2.5) 
					local bandit = game.ServerStorage.Bandit:Clone()
					bandit.HumanoidRootPart.CFrame = BanditSpawns:GetChildren()[math.random(1, #BanditSpawns:GetChildren())].CFrame + Vector3.new(0,10,0)
					bandit.Parent = workspace.AttackableNPCS
				until workspace.Sound3.Playing == false
				for i, v in ipairs(workspace.AttackableNPCS:GetChildren()) do
					v:Destroy()
				end
				for i, v in ipairs(workspace.FloppaBlocker.bandits:GetChildren()) do
					v:Destroy()
				end
				game.ReplicatedStorage.Bandit2:FireAllClients()
				workspace.Sound3:Stop()
				workspace.Sound:Play()
			end
			workspace.Mailbox.Main.Sparkles.Enabled = true
			workspace.Mailbox.Main.ProximityPrompt.Enabled = true
			mailboxcon = workspace.Mailbox.Main.ProximityPrompt.Triggered:Connect(function(plr)
				workspace.Mailbox.Main.Sparkles.Enabled = false
				workspace.Mailbox.Main.ProximityPrompt.Enabled = false
				local c = game.ServerStorage.mailboxthings:GetChildren()[math.random(1,#game.ServerStorage.mailboxthings:GetChildren())]:Clone()
				c.Parent = plr.PlayerGui
				mailboxcon:Disconnect()
				mailboxcon = nil
			end)
		end
		game.ServerStorage.TempData.CanGiveRent.Value = true
		workspace.Roommate.Head.Dialog["Gimme rent"].ResponseDialog = "Alright"
	end
end)

while true do
	task.wait(0.05)
	Time:SetMinutesAfterMidnight(Time:GetMinutesAfterMidnight()+0.5)
end
